टिंकर एक पायथन लाइब्रेरी है जिसका उपयोग जीयूआई-आधारित एप्लिकेशन बनाने के लिए किया जाता है। मान लीजिए कि हमें एक कार्यात्मक अनुप्रयोग बनाना है जिसमें एक विशेष फ़ंक्शन को लूप में परिभाषित किया गया है। रिकर्सिव फ़ंक्शन अनंत समय के लिए लेबल विजेट में कुछ टेक्स्ट प्रदर्शित करेगा।
इस पुनरावर्ती फ़ंक्शन को रोकने के लिए, हम एक फ़ंक्शन को परिभाषित कर सकते हैं जो एक बटन पर क्लिक करने पर स्थिति को बदल देता है। एक वैश्विक चर घोषित करके स्थिति को बदला जा सकता है जो या तो सही या गलत हो सकता है।
उदाहरण
# Import the required library
from tkinter import *
# Create an instance of tkinter frame
win= Tk()
# Set the size of the Tkinter window
win.geometry("700x350")
# Define a function to print something inside infinite loop
run= True
def print_hello():
if run:
Label(win, text="Hello World", font= ('Helvetica 10 bold')).pack()
# After 1 sec call the print_hello() again
win.after(1000, print_hello)
def start():
global run
run= True
def stop():
global run
run= False
# Create buttons to trigger the starting and ending of the loop
start= Button(win, text= "Start", command= start)
start.pack(padx= 10)
stop= Button(win, text= "Stop", command= stop)
stop.pack(padx= 15)
# Call the print_hello() function after 1 sec.
win.after(1000, print_hello)
win.mainloop() आउटपुट

अब, जब भी हम "रोकें" बटन पर क्लिक करते हैं, तो यह फ़ंक्शन को कॉल करना बंद कर देगा।