Tkinter ইভেন্ট বাইন্ড করতে বাম মাউস বাটন হোল্ড করার সাথে, আমরা নিচের পদক্ষেপগুলো নিতে পারি −
tkinter ফ্রেমের একটি ইনস্ট্যান্স তৈরি করুন।
win.geometry মেথড ব্যবহার করে ফ্রেমের আকার সেট করুন।
একটি ইভেন্ট হ্যান্ডলার "handler1" সংজ্ঞায়িত করুন একটি স্টেটমেন্ট প্রিন্ট করার জন্য যখন মাউস মুভ করছে বাম বাটন চাপা থাকা অবস্থায়।
আর একটি ইভেন্ট হ্যান্ডলার "handler2" সংজ্ঞায়িত করুন একটি স্টেটমেন্ট প্রিন্ট করার জন্য যখন মাউস বাটন রিলিজ হয়।
bind মেথড ব্যবহার করুন <B1-Motion> কে handler1-এর সাথে বাইন্ড করতে।
আরেকবার bind মেথড ব্যবহার করুন <ButtonRelease-1> কে handler2-এর সাথে বাইন্ড করতে।
অবশেষে, অ্যাপ্লিকেশন উইন্ডোর mainloop চালান।
উদাহরণ
# প্রয়োজনীয় লাইব্রেরি আমদানি করুন from tkinter import * # tkinter ফ্রেমের একটি ইনস্ট্যান্স তৈরি করুন win = Tk() # উইন্ডোর জ্যামিতি সংজ্ঞায়িত করুন win.geometry("750x250") # একটি ফাংশন সংজ্ঞায়িত করুন def handler1(e): print("You are moving the Mouse with the Left Button Pressed.") def handler2(e): print("Button Released") # মেইন উইন্ডোতে একটি লেবেল সংজ্ঞায়িত করুন Label(win, text="Move the Mouse with the Left Button Pressed", font='Helvetica 15 underline').pack(pady=30) # মাউস ইভেন্টগুলো হ্যান্ডলারের সাথে বাইন্ড করুন win.bind('', handler1) win.bind('', handler2) win.mainloop() আউটপুট
যখন আপনি কোডটি এক্সিকিউট করবেন, তবে এটি নিচের স্ক্রিনটি দেখাবে −

এখন, বাম বাটন চাপা রেখে মাউস মুভ করুন এবং এটি কনসোলে নিচের আউটপুটটি দেখাবে
You are moving the Mouse with the Left Button Pressed. You are moving the Mouse with the Left Button Pressed. You are moving the Mouse with the Left Button Pressed. You are moving the Mouse with the Left Button Pressed. You are moving the Mouse with the Left Button Pressed.
যখন আপনি মাউসের বাম বাটন রিলিজ করবেন, তবে এটি নিচেরটি দেখাবে −
Button Released