Tkinter के साथ, हम Threading का उपयोग करके एक समय में multiple functions call कर सकते हैं। यह एप्लिकेशन में कुछ functions के asynchronous execution को प्रदान करता है।
Python में thread का उपयोग करने के लिए, हम threading नामक module import कर सकते हैं और इसकी Thread class को subclass कर सकते हैं। अपने नए class के अंदर, हमें Run method को overwrite करना होगा और वहां अपनी logic perform करनी होगी।
तो basically threading के साथ, हम एक समय में multiple work कर सकते हैं। अपने एप्लिकेशन में threading achieve करने के लिए, Tkinter Thread() फंक्शन प्रदान करता है।
आइए एक उदाहरण लें और एक thread बनाएं जो कुछ समय के लिए sleep करेगी और फिर parallel में दूसरी function execute करेगी।
इस उदाहरण के लिए, हम Time module और Tkinter library में परिभाषित threading module import करेंगे।
उदाहरण
# Import all the necessary libraries
from tkinter import *
import time
import threading
# Define the tkinter instance
win = Tk()
# Define the size of the tkinter frame
win.geometry("700x400")
# Define the function to start the thread
def thread_fun():
label.config(text="You can Click the button or Wait")
time.sleep(5)
label.config(text="5 seconds Up!")
label = Label(win)
label.pack(pady=20)
# Create button
b1 = Button(win, text="Start", command=threading.Thread(target=thread_fun).start())
b1.pack(pady=20)
win.mainloop()
आउटपुट
उपरोक्त code चलाने से एक button और एक thread बनेगा जो label पर काम करता है।

5 seconds के बाद, thread automatically pause हो जाएगा।
