Reputation: 53
I made a Python GUI using Tkinter, but when I run it directly (double click the file) it opens the black python window but automatically closes by itself in less than half a second. I found a way to make it open the IDLE editor but it just opens the editor and doesn't run it.
I want it to run the way it runs when you open the IDLE editor and press Run Module. This runs it using Python Shell.
Is there a way I can make it automatically run using Python Shell?
Upvotes: 2
Views: 1326
Reputation: 53
Okay, one of the comments on the original question is correct.
As Terry Jan Reedy (user:722804) said,
It is possible that your mygui.py file is missing 'root.mainloop()' or the equivalent to start the GUI. IDLE lets you omit that during development so that one can interact with tkinter to retrieve values and make changes to widgets.
Adding gui.mainloop()
to the end of my program worked.
Upvotes: 1
Reputation: 18796
Based on Mark Tolonen's comment you should do two things
rename your file to a .pyw
from .py
to prefer console-less runs
set your system to open .pyw
files with pythonw
if that's not configured already
pythonw.exe
executable)Upvotes: 1