Tkinter হল একটি পাইথন লাইব্রেরি যা GUI-ভিত্তিক অ্যাপ্লিকেশন তৈরি করতে ব্যবহৃত হয়। ধরা যাক আমাদের একটি কার্যকরী অ্যাপ্লিকেশন তৈরি করতে হবে যেখানে একটি নির্দিষ্ট ফাংশন একটি লুপে সংজ্ঞায়িত করা হয়েছে। পুনরাবৃত্ত ফাংশন অসীম সময়ের জন্য একটি লেবেল উইজেটে কিছু পাঠ্য প্রদর্শন করবে৷
এই পুনরাবৃত্ত ফাংশনটি বন্ধ করার জন্য, আমরা একটি ফাংশন সংজ্ঞায়িত করতে পারি যা যখনই একটি বোতামে ক্লিক করা হয় তখন অবস্থা পরিবর্তন করে। একটি বিশ্বব্যাপী পরিবর্তনশীল ঘোষণা করে শর্তটি পরিবর্তন করা যেতে পারে যা সত্য বা মিথ্যা হতে পারে।
উদাহরণ
# 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() আউটপুট

এখন, যখনই আমরা "স্টপ" বোতামে ক্লিক করি, এটি ফাংশনটিকে কল করা বন্ধ করে দেবে৷
৷