Meleon
Meleon

Reputation: 9

Tkinter commands are always after commands like print(), Input(), etc.?

Here is my code (It is not ready yet.)

# NumbrimängGUI/NumberGameGUI

from time import *
from random import *
from tkinter import *
from datetime import *

# Keele valimine/Choosing language

def Eesti ():
    sleep (0.25)
    global keel
    keel.destroy()
    global valik
    valik = 'eesti'
    print ('Hea kyll')
def Inglismaa ():
    sleep (0.25)
    global keel
    keel.destroy()
    global valik
    valik = 'inglise'
    print ('All right!')

keel = Tk()
keel.title('NumbriMäng/NumberGame')
frame_keel = Frame(keel, width = 275, height = 150, bg = '#91aca4')
frame_keel.pack()
Eesti_nupp = Button(frame_keel, text = 'Eesti keel', command = Eesti)
Eesti_nupp.pack()
Eesti_nupp.place(width= 100, height = 100, x = 25, y= 25)
Inglismaa_nupp = Button(frame_keel, text = 'English', command = Inglismaa)
Inglismaa_nupp.pack()
Inglismaa_nupp.place(width= 100, height = 100, x = 150, y= 25)

sleep (5)

Don't pay too much attention to my variables (They are written in Estonian.)

Question:

When I run my code it seems like the first command what my code does is sleep (5) but i want my program to display my window with buttons first and then wait 5 seconds. Can someone explain me what is going on?

Also sorry for my bad english Im from Estonia :D Thanks

Upvotes: 0

Views: 33

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43166

Your GUI won't do anything until you call keel.mainloop(). And using time.sleep() in a GUI program is generally a bad idea, take a look at the .after function.

Upvotes: 1

Related Questions