我使用m trying to make a GUI calculator, a very basic one, it only has division, subtraction, addition, and multiplication. I use the Tkinter module. I make buttons, labels, and entry widgets, then display them with
pack()function, everything is going smoothly, and then I change it to use
grid()'函数来美化事物。当我测试它时,显示了以下消息_tkinter.TclError: bad option "-row": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side
这是我的完整代码
from tkinter import *
add_sign = "+"
sub_sign = "-"
tms_sign = "x"
div_sign = ":"
root = Tk()
operation_sign_string = StringVar()
operation_sign = Label(textvariable=operation_sign_string)
inputA = Entry(bd=3)
inputB = Entry(bd=3)
def add_onclick():
operation_sign_string.set(add_sign)
def sub_onclick():
operation_sign_string.set(sub_sign)
def tms_onclick():
operation_sign_string.set(tms_sign)
def div_onclick():
operation_sign_string.set(div_sign)
add = Button(text="+", command=add_onclick)
sub = Button(text="-", command=sub_onclick)
tms = Button(text="x", command=tms_onclick)
div = Button(text=":", command=div_onclick)
add.grid(column=1, row=2)
sub.grid(column=2, row=2)
tms.grid(column=3, row=2)
div.grid(column=4, row=2)
operation_sign.grid(column=2, row=1)
inputA.grid(column=1, row=1)
inputB.pack(column=3, row=1)
root.mainloop()
我只尝试了一种方法,将属性的顺序从grid(row=1 column=1)
切换为grid(column=1, row=1)
,这样就将错误从_tkinter.TclError: bad option "-row": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side
更改为_tkinter.TclError: bad option "-column": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side
我完全不知道为什么tkinter会吐出这个错误。
1条答案
按热度按时间lb3vh1jj1#
就像在评论中提到的,如果你使用压缩几何管理器,你不能使用行或列。这些选项属于网格几何管理器。
第43行应改为:输入B.网格(列=3,行=1)