Home > Enterprise >  Why does this code only runs properly in only the python shell
Why does this code only runs properly in only the python shell

Time:07-08

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

CodePudding user response:

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()

Happy Coding and Welcome to Stackoverflow!

  • Related