Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I add a time delay to a tkinter Label?

I’m creating a Treasure Island type game with tkinter and I’m trying to add a delay before the label "line1" appears in the GUI, I’ve tried the after function but I don’t know how I would properly implement it. Anyway here’s the code:

import time
import tkinter
window = tkinter.Tk()

window.title("Treasure Island")
window.geometry("500x500")

logo = tkinter.Label(window, text='''
          |                   |                  |                     |
 _________|________________.=""_;=.______________|_____________________|_______
|                   |  ,-"_,=""     `"=.|                  |
|___________________|__"=._o`"-._        `"=.______________|___________________
          |                `"=._o`"=._      _`"=._                     |
 _________|_____________________:=._o "=._."_.-="'"=.__________________|_______
|                   |    __.--" , ; `"=._o." ,-"""-._ ".   |
|___________________|_._"  ,. .` ` `` ,  `"-._"-._   ". '__|___________________
          |           |o`"=._` , "` `; .". ,  "-._"-._; ;              |
 _________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
|                   | |o;    `"-.o`"=._``  '` " ,__.--o;   |
|___________________|_| ;     (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._    "      `".o|o_.--"    ;o;____/______/______/____
/______/______/______/_"=._o--._        ; | ;        ; ;/______/______/______/_
____/______/______/______/__"=._o--._   ;o|o;     _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
''')

logo.pack()
logo.config(font=('length', 15))

line1 = tkinter.Label(window, text="Welcome to Treasure Island,\n"
                                   "Your goal is to find the buried Treasure!")
line1.pack()
line1.config(font=('length', 15))

window.mainloop()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for delay, you can use after method that take two arg
first arg time by millisecond and second arg is a function
more detail see

def callback():
  line1 = tkinter.Label(window, text="Welcome to Treasure Island,\n"
                                   "Your goal is to find the buried Treasure!")
  line1.pack()
  line1.config(font=('length', 15))


window.after(3000, callback) #time by milisecond
 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading