CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Button Binding Does Not Work

Open avalon60 opened this issue 2 years ago • 2 comments

I cannot get button binding to work. I have the following 2 examples. One is using tkinter, the other uses customtkinter. The only difference is in the button widget:

tkinter:


import tkinter as tk
import customtkinter as ctk

root = tk.Tk()
root.geometry("200x200")
widget_frame = tk.Frame(root).grid(row=1, column=1)


def right_click(x):
    print('right clicked')
    print(x)


def left_click():
    print('left clicked')


lbl_property = tk.Label(master=widget_frame, text='Label')
lbl_property.grid(row=0, column=0, sticky='w')
btn_property = tk.Button(master=widget_frame,
                         text='button',
                         command=left_click
                         )
btn_property.grid(row=0, column=1, padx=5, pady=5)
param = 'some parameter'
btn_property.bind("<Button-3>", lambda event, x=param: right_click(x))

root.mainloop()

and with customtkinter:

import tkinter as tk
import customtkinter as ctk

root = tk.Tk()
root.geometry("200x200")
widget_frame = tk.Frame(root).grid(row=1, column=1)


def right_click(x):
    print('right clicked')
    print(x)

def left_click():
    print('left clicked')


lbl_property = tk.Label(master=widget_frame, text='Label')
lbl_property.grid(row=0, column=0, sticky='w')
btn_property = ctk.CTkButton(master=widget_frame,
                             text='button',
                             command=left_click
                             )
btn_property.grid(row=0, column=1, padx=5, pady=5)
param='some parameter'
btn_property.bind("<Button-3>", lambda event, x=param: right_click(x))

root.mainloop()

When these are both executed, the left click works for both (I am on Linux). However the right click (Button-3) only works in the tkinter example.

avalon60 avatar Sep 24 '22 09:09 avalon60

Binding will work in the next version 5.0.0, which will be released soon.

TomSchimansky avatar Oct 07 '22 14:10 TomSchimansky

Great thanks for the update!

DestoGit avatar Nov 19 '22 19:11 DestoGit

Binding is now implemented with version 5.0.0.

TomSchimansky avatar Dec 06 '22 22:12 TomSchimansky