'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. 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.
Solution 1:[1]
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()
Moreover, you forgot to add in a b1.pack() after the b1 = Button()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Henry Ecker |
