10 examples of 'tkinter button click event' in Python

Every line of 'tkinter button click event' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
405def bind_click(self, callback, button=1):
406 """
407 Register a new callback that will be called whenever this
408 C{CanvasWidget} is clicked on.
409
410 @type callback: C{function}
411 @param callback: The callback function that will be called
412 whenever this C{CanvasWidget} is clicked. This function
413 will be called with this C{CanvasWidget} as its argument.
414 @type button: C{int}
415 @param button: Which button the user should use to click on
416 this C{CanvasWidget}. Typically, this should be 1 (left
417 button), 3 (right button), or 2 (middle button).
418 """
419 self.__callbacks[button] = callback
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

12def OnClick(self, event):
13 self.button.SetLabel("Clicked")
184def tk_mouse_button_release(self, event: tkinter.Event) -> None:
185 """Handle tkinter mouse press events.
186
187 Args:
188 event (tkinter.Event): The mouse button release event
189 """
190 button = self._mouse_button_map.get(event.num)
191 if not button:
192 return
193
194 self._handle_mouse_button_state_change(button, False)
195 self._mouse_release_event_func(event.x, event.y, button)
24def button_event(b, e, t):
25 print(b.label)
58def buttonClick(element):
59 evt = doc().createEvent('MouseEvents')
60 mf = get_main_frame()
61 target = mf.EventTarget(element)
62 target.setptr(element.getptr()) # dreadful hack that actually works. wow.
63 evt.initMouseEvent("click", True, True, wnd(), 1, 0, 0, 0, 0, False,
64 False, False, False, 0, target)
65 element.dispatchEvent(evt)
435def unbind_click(self, button=1):
436 """
437 Remove a callback that was registered with C{bind_click}.
438
439 @type button: C{int}
440 @param button: Which button the user should use to click on
441 this C{CanvasWidget}. Typically, this should be 1 (left
442 button), 3 (right button), or 2 (middle button).
443 """
444 try: del self.__callbacks[button]
445 except: pass
32def mouseAction(self, event):
33 if event.Entering():
34 print 'enter'
35 self.bitmap = self.onbitmap
36 self.Refresh()
37 elif event.Leaving():
38 self.bitmap = self.offbitmap
39 print 'leave'
40 self.Refresh()
41 elif event.ButtonUp():
42 self.ClickedButton()
31def _btn_cb(self):
32 print "clicked"
472def clickHandler(self, event):
473 if self._busy():
474 return EVENT_HANDLED
475 return EVENT_HANDLED
382def MouseDown(self, evt):
383 self._selected = 1
384 #Custom event business
385 event = PSButtonEvent(myEVT_BTN_CLICKED, self.GetId())
386 event._evt_obj = self
387 self.GetEventHandler().ProcessEvent(event)
388 wx.CallAfter(self.Refresh)

Related snippets