唐舞麟 发表于 2021-5-22 20:53:03

新人求助

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

代码如下:

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


请大佬帮帮忙看是什么问题?

小伤口 发表于 2021-5-23 03:02:50

command应该放在button里面 ,而不是布局里面哦

唐舞麟 发表于 2021-5-23 07:48:10

小伤口 发表于 2021-5-23 03:02
command应该放在button里面 ,而不是布局里面哦

问题解决了,感谢大佬
页: [1]
查看完整版本: 新人求助