-1

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()
n0trad3an
  • 21
  • 6
  • 1
    This `tk = tk.Tk()` shadows `tk` the module with the `Tk` object, and creates a whole lot of problems. Rename it to something else and it should work. – Pietro Mar 29 '21 at 17:03
  • 1
    When asking questions about errors, please include the full error in your question. – Bryan Oakley Mar 29 '21 at 17:41

2 Answers2

3

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()
Pietro
  • 1,090
  • 2
  • 9
  • 15
2

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
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46