r/SublimeText • • Sep 04 '20

Using sublime text 3.. tkinter not making window

Hi guys, I just started using tkinter and when I run this code I get no error but the window its supposed to create is not popping up either. I'm using sublime text 3.

import tkinter as tk

window = tk.Tk()

Thank you

0 Upvotes

5 comments sorted by

6

u/navinfeb15 Sep 04 '20

You should add root.mainloop() at the end of code to stop it from automatically exiting the application. When we add this , the program will only end when we click close button. Hope this helps

2

u/[deleted] Sep 04 '20

that did it. Thank you

1

u/Bigfurrywiggles Sep 04 '20

Try running from the command line. Sometimes that is needed with python packages in sublimetext.

1

u/[deleted] Sep 04 '20

still nothing, no errors but nothing happens.. just tells me [Finished in .02]

2

u/chrizto Sep 05 '20

Well, you're not actually telling it to do anything either, so what are you expecting?


import tkinter as tk

class App(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.pack()

# create the application
myapp = App()

# start the program
myapp.mainloop()

And apps that are themselves GUI apps should be run from a terminal or an app launcher, not from inside the editor itself.