[英]Error when using window button in tkinter
Here is my code for debugging:这是我的调试代码:
from tkinter import *
window = Tk()
b1 = window.button(window,text="Dark",command=window.configure(bg='black'))
window.mainloop()
I want to add a button to set the bg color to black.我想添加一个按钮来将 bg 颜色设置为黑色。 Pretty simple.
很简单。 But it gives an error:
但它给出了一个错误:
Traceback (most recent call last):
File "C:/Users/----/Downloads/windows.py", line 3, in <module>
b1 = window.button(window,text="Dark",command=window.configure(bg='black'))
File "C:\Users\----\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2383, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'button'
I'm not sure how to fix this.我不确定如何解决这个问题。
I believe that this is the answer:我相信这就是答案:
from tkinter import *
window = Tk()
b1 = Button(window,text="Dark",command=window.configure(bg='black'))
b1.pack()
window.mainloop()
Your mistake was that your input was b1 = window.button()
instead of b1 = Button()
你的错误是你的输入是
b1 = window.button()
而不是b1 = Button()
Moreover, you forgot to add in a b1.pack()
after the b1 = Button()
此外,您忘记在
b1 = Button()
b1.pack()
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.