I think I made a mistake with this tkinter widget

50 views Asked by At

So till now I want to make a simple button but it gives me an error screen, what am I doing wrong? Here's my code:

import tkinter as tk
import math
import time

tk = tk.Tk()
tk.geometry()
tk.attributes("-fullscreen", True)

exit_button = tk.Button(tk, text = "Exit", height = 2, width = 2, command = tk.destroy)
exit_button.place(x=1506, y=0)





tk.mainloop()
2

There are 2 answers

0
Pietro On BEST ANSWER

You are shadowing tk with something else:

import tkinter as tk

root = tk.Tk()
root.geometry()
root.attributes("-fullscreen", True)

exit_button = tk.Button(root, text="Exit", height=2, width=2, command=root.destroy)
exit_button.place(x=1506, y=0)


tk.mainloop()
0
Delrius Euphoria On

You cannot use tk = tk.Tk(), because you are also referring to tkinter as tk. So either:

Change your imports(not recommended):

import tkinter as _tk

tk = _tk.Tk() # And so on..

or change your variable name(recommended):

root = tk.Tk() # And change tk.geometry to root.geometry() and so on