Issue 31483: ButtonPress event not firing until button release Python 3.6.1 (original) (raw)
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 or 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("", start_scrolling) xscroll.bind('', 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()
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('', down) app.bind('', 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('', down) label.bind('', up)
and I see the same expected behavior.