Reputation: 43
I have this code
from tkinter import *
root = Tk()
It works fine on the shell but not in the IDE
New Contributor ;) Also explain the reason
Thank you :)
Edit
IDE - PyCharm
Upvotes: 2
Views: 60
Reputation: 309
You will always need to call a mainloop()
at the end of the script
Why does that code works perfectly fine in the Python Shell?
Generally Speaking, The Python Shell
interprets only one line at a time and once you call the mainloop()
you won't be able to do anything with your tkinter
window so in python shell
it would be very inconvenient if you really think about it.
Your Updated Code
from tkinter import *
root = Tk()
root.mainloop()
Upvotes: 2
Reputation: 43
I would also like to point out that TkObject.mainloop()
also needs to be at the end of the script
Upvotes: 2