classification
Title: ButtonPress event not firing until button release Python 3.6.1
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.6
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: HobbyScript, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2017-09-15 13:17 by HobbyScript, last changed 2020-12-21 10:04 by serhiy.storchaka. This issue is now closed.

Messages (4)
msg302251 - (view) Author: Mike McDonnal (HobbyScript) Date: 2017-09-15 13:17
On my version of python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]

As well as on 3.6.2 for some other users I have spoken to there seams to be an issue with the event for pressing the mouse button down.

The event <Button-1> or <ButtonPress-1> do not fire when the mouse button is pressed but rather when the mouse button is released.

The following example code works fine on 2.7 but the button event is not working properly on at lease my version and 3.6.2

import Tkinter as tk
import ttk

app = tk.Tk()
t = ttk.Treeview(app)
t.pack(side="top",fill="both",expand=1)

scrolling = False
xscroll = tk.Scrollbar(app,command=t.xview,orient="horizontal")
t.configure(xscrollcommand=xscroll.set)
xscroll.pack(side="top",fill="x")

def scrolling_active(arrow, *args):
    global scrolling
    if scrolling == True:
        if arrow == "arrow1":
            t.xview('scroll', -5, 'units')
        if arrow == "arrow2":
            t.xview('scroll', 5, 'units')
        app.after(5, lambda a = arrow: scrolling_active(a))

def start_scrolling(event):
    global scrolling
    scrolling = True
    scrolling_active(xscroll.identify(event.x, event.y))

def stop_scrolling(event):
    global scrolling
    scrolling = False

xscroll.bind("<Button-1>", start_scrolling)
xscroll.bind('<ButtonRelease-1>', stop_scrolling)

tcols = ["header " + str(i)
         for i in range(50)]
t.config(columns=tcols)
for h in tcols:
    t.heading(h,text=h)

for i in range(5):
    t.insert("","end",
             text = "item" + str(i),
             values = ["value" + str(x) for x in range(49)])
app.geometry("{}x{}".format(400, 300))

app.mainloop()
msg302252 - (view) Author: Mike McDonnal (HobbyScript) Date: 2017-09-15 13:18
OS Version - Windows 7 Pro
msg302289 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-15 18:34
I cannot reproduce the claimed bug on Win 10, 2.7.13 and 3.6.2, 64 bit amd versions.  Running the code above from console or IDLE, I see no difference.  Button press selects item, add blue background.  Release changes nothing.

Here is a minimal demo that runs on both 2 and 3.

try:
    import tkinter as tk
    from tkinter import ttk
except:
    import Tkinter as tk
    import ttk

def down(event): print('down')
def up(event): print('up')

app = tk.Tk()
app.bind('<Button-1>', down)
app.bind('<ButtonRelease-1>', up)
app.mainloop()

Button down prints 'down', button up prints 'up'.  No bug.

Replace the binds with

label = ttk.Label(app, text='test')
label.pack()
label.bind('<Button-1>', down)
label.bind('<ButtonRelease-1>', up)

and I see the same expected behavior.
msg383504 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-12-21 10:04
And in any case Tkinter is just a wrapper around Tk. If there is a bug it should be reported on the Tk bug tracker.
History
Date User Action Args
2020-12-21 10:04:06serhiy.storchakasetstatus: open -> closed
resolution: third party
messages: + msg383504

stage: resolved
2017-09-15 18:34:43terry.reedysetnosy: + serhiy.storchaka, terry.reedy, - paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg302289
components: + Tkinter, - Windows
2017-09-15 13:18:25HobbyScriptsetmessages: + msg302252
2017-09-15 13:17:31HobbyScriptcreate