Tkinter GUI based applications और games बनाने और develop करने के लिए व्यापक रूप से उपयोग किया जाता है। Tkinter अपना window या frame प्रदान करता है जहां हम अन्य attributes के साथ अपने programs और functions execute करते हैं।
मान लीजिए हम किसी particular एप्लिकेशन के साथ काम कर रहे हैं और हम application चलाते समय code में changes लिखना चाहते हैं। Tkinter एक callback method प्रदान करता है जिसका उपयोग window को चलाते हुए iterate करने के लिए किया जा सकता है। हम after(duration, task) method का उपयोग करके window को चलते रख सकते हैं जो basically duration के बाद changes चलाएगा।
इस उदाहरण में, हम एक window बनाएंगे जो main window या frame display करते समय console पर range (0 से 9) में numbers print करता है।
उदाहरण
# Import the required libraries
from tkinter import *
from tkinter import messagebox
# Create an instance of tkinter frame or window
win = Tk()
# Set the geometry
win.geometry("700x200")
# Define the function for button
def some_task():
for i in range(10):
print(i)
# Recursively call the function
win.after(2000, some_task)
# Keep Running the window
win.after(2000, some_task)
win.mainloop()
आउटपुट
उपरोक्त code चलाने से console पर range (0 से 9) में numbers print होते रहेंगे, और साथ ही, यह main window display करेगा।
0 1 2 3 4 5 6 7 8 9 ….
