属性错误: 'tuple'对象没有属性'place'



我是Python新手,从未编写过自己的脚本

代码段:

btn = Button=("text=Clicks 0", "background=#555", "foreground=#ccc",
"padx=20", "pady=8", "font=16", "command:click_button" )
btn.place(relx=.5, rely=.5, anchor="c", height=30, wigth=130  )
错误:

Traceback (most recent call last):
File "main.py", line 20, in <module>
btn.place(relx=.5, rely=.5, anchor="c", height=30, wigth=130  )
AttributeError: 'tuple' object has no attribute 'place'

为什么它给我错误,我怎么能解决它?

您有btn = Button=(...)。第二个等号不应该在这里。你只需要btn = Button(...)

尝试:

from tkinter import button

btn = Button("text=Clicks 0", "background=#555", "foreground=#ccc",
"padx=20", "pady=8", "font=16", "command:click_button" )
btn.place(relx=.5, rely=.5, anchor="c", height=30, wigth=130  )

最新更新