CustomTkinter
CustomTkinter copied to clipboard
Button Binding Does Not Work
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.
Binding will work in the next version 5.0.0, which will be released soon.
Great thanks for the update!
Binding is now implemented with version 5.0.0.