Home > Software engineering >  PYTHON use nother key like "ENTER" key
PYTHON use nother key like "ENTER" key

Time:09-22

I have a ComboBox in TKinter from Which i can select an option from a drop down menu. This works with either mouse click or ENTER key. I want to do the same but with RIGHT key.

box1 = ttk.Combobox(root, values=different_values)
def boxenter():
    #quasi ENTER key functionlity

box1.bind("<Right>",boxenter)

CodePudding user response:

You need to bind on the Listbox widget created internally and this internal Listbox widget can be accessed by calling TCL command:

box1 = ttk.Combobox(root, values=different_values)

def boxenter(event):
    # simulate "Enter" key
    box1.event_generate('<Return>')

# get the popdown listbox created internally by TCL interpreter
popdown = box1.tk.eval(f'ttk::combobox::PopdownWindow {box1}')   '.f.l'
# call the undocumented _bind()
box1._bind(('bind', popdown), '<Right>', boxenter, None)
  • Related