Python Forum
[Tkinter] Mouse click without use bind
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Mouse click without use bind
#3
Where is drag and drop mentioned?

If you want to force a 3 second continuous touch before doing some action, you'll need to at least bind to touch and release and use an after to call your eventual callback.
from tkinter import *
after_id = None
root = Tk()

def press_cb(event):
    global after_id
    after_id = root.after(3000, after_cb)

def release_cb(event):
    global after_id
    if after_id is not None:
        root.after_cancel(after_id)
        after_id = None

def after_cb():
    """Do whatever"""
    print('Leg go of me!!')

root.bind('<ButtonPress-1>', press_cb)
root.bind('<ButtonRelease-1>', release_cb)
Or you could combine a few things.
from tkinter import *

root = Tk()

def press_cb(event=None):
    global lp_id
    if event is None:
        print('Let go my Eggo!')
        lp_id = None
    elif event.type == EventType.ButtonPress:
        lp_id = root.after(3000, press_cb)
    elif lp_id:
        root.after_cancel(lp_id)
        lp_id = None

root.bind('<ButtonPress-1>', press_cb)
root.bind('<ButtonRelease-1>', press_cb)
It would be useful to know what you are trying to do, what you have tried to do, and why you are unhappy with what you've done. At least I am confused about what you are asking.
Reply


Messages In This Thread
Mouse click without use bind - by ATARI_LIVE - Oct-01-2020, 11:59 AM
RE: Mouse click without use bind - by Larz60+ - Oct-01-2020, 05:35 PM
RE: Mouse click without use bind - by deanhystad - Oct-01-2020, 07:40 PM
RE: Mouse click without use bind - by Larz60+ - Oct-02-2020, 01:26 AM
RE: Mouse click without use bind - by ATARI_LIVE - Oct-02-2020, 09:18 AM
RE: Mouse click without use bind - by ATARI_LIVE - Oct-06-2020, 07:40 AM
RE: Mouse click without use bind - by deanhystad - Oct-06-2020, 05:46 PM
RE: Mouse click without use bind - by joe_momma - Oct-21-2020, 03:08 PM
RE: Mouse click without use bind - by ATARI_LIVE - Oct-23-2020, 10:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - touchscreen, push the button like click the mouse John64 5 938 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  [Tkinter] bind menator01 1 1,275 Apr-15-2022, 08:47 PM
Last Post: menator01
  [Tkinter] bind lambda keypress counter knoxvilles_joker 15 7,921 Apr-19-2021, 01:56 AM
Last Post: knoxvilles_joker
  [Tkinter] program unresponsive during pynput mouse click RobotTech 1 3,529 May-07-2020, 04:43 PM
Last Post: RobotTech
  [Kivy] AttributeError: 'NoneType' object has no attribute 'bind' faszination_92 2 6,325 Apr-12-2020, 07:01 PM
Last Post: Larz60+
  [WxPython] Bind error PeterLinux 1 2,270 Apr-06-2020, 03:07 AM
Last Post: joe_momma
  Tkinter:Unable to bind and unbind function with a button shallanq 2 5,077 Mar-28-2020, 02:05 AM
Last Post: joe_momma
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 3,804 Dec-16-2019, 04:47 AM
Last Post: woooee
  [Tkinter] How to bind an event when enter is pressed on a Entry control? Michael4 4 3,991 Aug-29-2019, 10:11 PM
Last Post: Michael4
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,066 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020