Tkinter इवेंट को बाएं माउस बटन दबाए रखने पर बाइंड करने के लिए, हम निम्नलिखित चरण अपना सकते हैं:
Tkinter फ्रेम का एक इंस्टेंस बनाएं।
win.geometry मेथड का उपयोग करके फ्रेम का आकार सेट करें।
एक इवेंट हैंडलर "handler1" परिभाषित करें जो माउस को बाएं बटन के साथ दबाकर ले जाने पर स्टेटमेंट प्रिंट करे।
एक और इवेंट हैंडलर "handler2" परिभाषित करें जो माउस बटन छोड़ने पर स्टेटमेंट प्रिंट करे।
बाइंड मेथड का उपयोग करके <B1-Motion> को handler1 के साथ बाइंड करें।
फिर से बाइंड मेथड का उपयोग करके <ButtonRelease-1> को handler2 के साथ बाइंड करें।
अंत में, एप्लिकेशन विंडो का mainloop चलाएं।
उदाहरण
# Import required libraries from tkinter import * # Create an instance of tkinter frame win = Tk() # Define the geometry of the window win.geometry("750x250") # Define a function def handler1(e): print("You are moving the Mouse with the Left Button Pressed.") def handler2(e): print("Button Released") # Define a Label in Main window Label(win, text="Move the Mouse with the Left Button Pressed", font='Helvetica 15 underline').pack(pady=30) # Bind the Mouse events with the Handler 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