0
import tkinter as tk
import threading
import time

def count(timeamt):
    time.sleep(timeamt)
    tk.Label(win, text='5 sec done').grid(row = 0, column = 1)

def start():
    t1 = threading.Thread(target=count, args=(5))
    t1.start()
    # count(5)
    tk.Label(win, text = 'started').grid(row = 1, column = 1)

win = tk.Tk()
win.geometry('200x200')

tk.Button(win, text = "hi", command = start).grid(row = 2, column = 5)

win.mainloop()

This is not working

Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
TypeError: count() argument after * must be an iterable, not int
TheLizzard
  • 7,248
  • 2
  • 11
  • 31

1 Answers1

1

Try this:

import tkinter as tk
import time

def count():
    label = tk.Label(win, text="5 sec done")
    label.grid(row=0, column=1)

def start():
    # 5 sec = 5000 ms
    win.after(5000, count)
    label = tk.Label(win, text="started")
    label.grid(row=1, column=1)

win = tk.Tk()
win.geometry("200x200")

btn = tk.Button(win, text="hi", command=start)
btn.grid(row=2, column=5)

win.mainloop()

I removed the thread and used win.after instead. For more info on the .after method read this

TheLizzard
  • 7,248
  • 2
  • 11
  • 31