鱼C论坛

 找回密码
 立即注册
查看: 1947|回复: 2

[技术交流] 新人求助

[复制链接]
发表于 2021-5-22 20:53:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
最近遇到了点困难,一直想不明白,就过来求助了

代码如下:
import tkinter.messagebox


from tkinter import *


root = Tk()
nuber = "0"


def _01():
    global nuber
    if nuber == "0":
        nuber = "1"
    else:
        nuber = nuber + "1"

def _02():
    global nuber
    if nuber == "0":
        nuber = "2"
    else:
        nuber = nuber + "2"

def _03():
    global nuber
    if nuber == "0":
        nuber = "3"
    else:
        nuber = nuber + "3"

def _04():
    global nuber
    if nuber == "0":
        nuber = "4"
    else:
        nuber = nuber + "4"

def _05():
    global nuber
    if nuber == "0":
        nuber = "5"
    else:
        nuber = nuber + "5"

def _06():
    global nuber
    if nuber == "0":
        nuber = "6"
    else:
        nuber = nuber + "6"

def _07():
    global nuber
    if nuber == "0":
        nuber = "7"
    else:
        nuber = nuber + "7"

def _08():
    global nuber
    if nuber == "0":
        nuber = "8"
    else:
        nuber = nuber + "8"

def _09():
    global nuber
    if nuber == "0":
        nuber = "9"
    else:
        nuber = nuber + "9"

def _00():
    global nuber
    if nuber == "0":
        pass
    else:
        nuber = nuber + "0"


button_01 = Button(root,text = " 1 ").grid(row = 0,column = 1,padx = 10,pady = 5,command = _01)

button_02 = Button(root,text = " 2 ").grid(row = 0,column = 2,padx = 10,pady = 5,command = _02)

button_03 = Button(root,text = " 3 ").grid(row = 0,column = 3,padx = 10,pady = 5,command = _03)

button_04 = Button(root,text = " 4 ").grid(row = 1,column = 1,padx = 10,pady = 5,command = _04)

button_05 = Button(root,text = " 5 ").grid(row = 1,column = 2,padx = 10,pady = 5,command = _05)

button_06 = Button(root,text = " 6 ").grid(row = 1,column = 3,padx = 10,pady = 5,command = _06)

button_07 = Button(root,text = " 7 ").grid(row = 2,column = 1,padx = 10,pady = 5,command = _07)

button_08 = Button(root,text = " 8 ").grid(row = 2,column = 2,padx = 10,pady = 5,command = _08)

button_09 = Button(root,text = " 9 ").grid(row = 2,column = 3,padx = 10,pady = 5,command = _09)

button_00 = Button(root,text = " 0 ").grid(row = 3,column = 1,padx = 10,pady = 5,command = _00)

button_10 = Button(root,text = " .  ").grid(row = 3,column = 2,padx = 10,pady = 5)

button_11 = Button(root,text = " = ").grid(row = 3,column = 3,padx = 10,pady = 5)

button_12 = Button(root,text = " + ").grid(row = 0,column = 4,padx = 10,pady = 5)

button_13 = Button(root,text = " - ").grid(row = 1,column = 4,padx = 10,pady = 5)

button_14 = Button(root,text = " * ").grid(row = 2,column = 4,padx = 10,pady = 5)

button_15 = Button(root,text = " / ").grid(row = 3,column = 4,padx = 10,pady = 5)


mainloop()

一运行就报错:

Traceback (most recent call last):
  File "E:\123\python\pythonXM\计算机2.0.py", line 83, in <module>
    button_01 = Button(root,text = " 1 ").grid(row = 0,column = 1,padx = 10,pady = 5,command = _01)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39-32\lib\tkinter\__init__.py", line 2485, in grid_configure
    self.tk.call(
_tkinter.TclError: bad option "-command": must be -column, -columnspan, -in, -ipadx, -ipady, -padx, -pady, -row, -rowspan, or -sticky


请大佬帮帮忙看是什么问题?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-5-23 03:02:50 From FishC Mobile | 显示全部楼层
command应该放在button里面 ,而不是布局里面哦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2021-5-23 07:48:10 | 显示全部楼层
小伤口 发表于 2021-5-23 03:02
command应该放在button里面 ,而不是布局里面哦

问题解决了,感谢大佬
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-15 17:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表