简体   繁体   English

python 3.6 使用 .grid 时 Tkinter 标签属性错误

[英]python 3.6 Tkinter Label attribute error when using .grid

I am beginning to get the hang of tkinter, but I have run into a problem.我开始掌握 tkinter 的窍门,但遇到了问题。 I want to create a label that displays an appropriate message according to the values of an Entry field, checked by a button.我想创建一个标签,根据条目字段的值显示适当的消息,通过按钮检查。 When this is used repeatedly, using just the tk.Label command will just overlay on top of the existing label, So I am trying to assign the label to a variable:当重复使用时,只使用 tk.Label 命令只会覆盖在现有标签的顶部,所以我试图将标签分配给一个变量:

messagebox=tk.Label(root2,text="                       ",font(style,font).grid(row=1,column=0,columnspan = 50))

I want to later on use the .configure command to change this text, However I get this error:我想稍后使用 .configure 命令来更改此文本,但是我收到此错误:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:[CENSORED BY POSTER (me), It was just the file directory]", line 84, in Checkpass
messagebox = tk.Label(root2,text="                       ",font=(style,font).grid(row=1,column=0,columnspan = 50))
AttributeError: 'tuple' object has no attribute 'grid'

Can anyone please tell me what I am doing wrong and explain why it wont work.谁能告诉我我做错了什么并解释为什么它不起作用。 Thank you, Tava谢谢你,塔瓦

Check your parentheses at font(style,font).grid .检查font(style,font).grid处的括号。 Probably should be:大概应该是:

messagebox=tk.Label(root2,text="                       ",font(style,font)).grid(row=1,column=0,columnspan = 50)

But I personally recommend split it into two lines for the sake of readability:但我个人建议为了可读性将它分成两行:

messagebox = tk.Label(root2, text="                       ", font(style, font))
messagebox.grid(row=1, column=0, columnspan = 50)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM