Wesley
Wesley

Reputation: 113

tkinter not working in spyder - tk._test() works

tkinter is only partially working for me. The tk._test() works, and when the backend is inline, tkinter does not work, but if I switch it to Tkinter after having tried running the below code with the Graphics backend set to inline, a bunch of tkinter windows will appear. Unfortunately, that is all. If I try running tkinter from then out, no new popups will appear. Nothing seems to happen, it is as if it get frozen.

This is what I am trying to run

import tkinter as tk

window = tk.Tk()
greeting = tk.Label(text="Hello, Tkinter")
greeting.pack()

I am running python 3.8.8. I can't figure out what version spyder is... but it isn't the latest one.

Upvotes: 0

Views: 766

Answers (2)

toyota Supra
toyota Supra

Reputation: 4564

You are missing window.mainloop().

import tkinter as tk

window = tk.Tk()
greeting = tk.Label(text="Hello, Tkinter")
greeting.pack()    
window.mainloop()

Result output image:

enter image description here

Upvotes: 0

Programmer
Programmer

Reputation: 61

Try this code:

import tkinter as tk
window = tk.Tk()
greeting = tk.Label(window, text="Hello, Tkinter")
greeting.pack()

You forgot to add the window when creating the Label.

Upvotes: 1

Related Questions