-1

Why does this code show nothing? What is wrong here?

import tkinter
import tkinter.font as tkFont
window=tkinter.Tk()
window.geometry("720x720")
fontStyle = tkFont.Font(family="Verdana", size=50)
tkinter.Label(window, text = "HELLO", font=fontStyle).pack()
tkinter.Label(window, text = "HELLO", font=fontStyle).pack()
from time import sleep
for i in range(0,10):
    tkinter.Label(window, text = i, font=fontStyle).pack()
    sleep(3)

I was trying to show all the outputs of the python code on a GUI window rather than the idle.

Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34
  • Use `.after()` to replace the for loop and add `window.mainloop()` at the end of the script. – acw1668 Mar 23 '20 at 11:47
  • Read [`sleep()` block the `.mainloop`](https://stackoverflow.com/a/58377804/7414759) and [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop) – stovfl Mar 23 '20 at 14:01

1 Answers1

0

You aren't starting the tkinter main loop.

Add

window.mainloop()

at the end (but do remember that tkinter then has control over your program).

AKX
  • 152,115
  • 15
  • 115
  • 172