Tkinter: root.after to run the code after an interval of time

How to run some code after some seconds with ‘after’.

import tkinter as tk


def back():
  lab["text"] = "Click"


def pprint():
  lab["text"] = "You clicked"
  root.after(1000, back)


# ===== GUI ==== #
root = tk.Tk()

lab = tk.Label(root,
  text="Hello World!", font="Arial 36")
lab.grid(row=0, column=1)

button = tk.Button(root, text="Click", font="Arial 36")
button.grid(row=0, column=0)
button["command"] = pprint

root.mainloop()

See the code in action

Tkinter on repl.it

https://repl.it/@EducationalChan/newtkinter?lite=true

Advertisement