0

I am new with python , And since i started python the command call in Tkinter never works for me I have tried all the ways and i took of the brakets off but it doesn't work still i have seen the related topics here but they didn't work for me here is a simple code that i have tried noting that when i clic the button nothing happens so where is the problem coming from?

from tkinter import *
if __name__ == "__main__":
    
    root = Tk()
    root.geometry("400x400")
    compile_button=Button(root,text="Compiler",command=root.quit)
    compile_button.pack()
Isra_Yas
  • 33
  • 3

1 Answers1

0
  1. Add root.mainloop() at the end of your __main__. So the GUI starts working. For further info check out this question.
  2. You can also use root.destroy method.

The whole code:

from tkinter import *

if __name__ == "__main__":
    root = Tk()
    root.geometry("400x400")
    compile_button=Button(root,text="Compiler", command=root.quit)
    compile_button.pack()
    root.mainloop()
Jakub Szlaur
  • 1,852
  • 10
  • 39