Reputation: 41
I am trying to take some of my codes that have a command line interface and give them GUI's. However, I am running into a problem. Can anyone help me understand why when I run my code from a file, nothing happens, but if I run it interactively, it works fine? A simple example is below. BTW, I am running Python 3.8.1 on Windows 10. Thanks in advance!
import tkinter as tk
import tkinter.ttk as ttk
#--------------------------
window = tk.Tk()
window.title('Test Window')
window.geometry('1000x800')
Upvotes: 0
Views: 1295
Reputation: 386210
This is because you don't call the mainloop
function. Tkinter automatically processes events when run interactively, but you need to explicitly start the event loop when not running interactively. Your code is running, but because you never tell it to start listening for events it exits at the end of the file just like any other python script.
You should add window.mainloop()
as the last line in your file.
Upvotes: 1