So I was trying to make a frameless and centred Tkinter window with a close button. I’m using VSCode on Macbook Pro. When I ran it, it said
close_button = root.Button(root, text = 'Close', command = root.quit)
^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py", line 2433, in __getattr__
return getattr(self.tk, attr)
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_tkinter.tkapp' object has no attribute 'Button'
And here is my code:
root = Tk()
root.configure(background = 'gray')
root.attributes('-alpha', 0.8)
root.minsize(160, 120)
root.maxsize(160, 120)
root.eval('tk::PlaceWindow . center')
root.overrideredirect(True)
close_button = root.Button(root, text = 'Close', command = root.quit)
close_button.pack()
root.mainloop()
Should I place the root.overrideredirect(True)
after I made the button, right before root.mainloop()
? I did research and couldn’t find anything I could understand. Sorry if it the problem is a bit vague, how do I get rid of the error while keeping everything how its supposed to be like, including the close button?
New contributor
Paulio Gaming is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.