Bind event on combobox item hover

3.3k Views Asked by At

Here is example of simple ttk dialog to demonstrate my problem:

from Tkinter import *
import ttk

items = ["Item %d" % (i+1,) for i in range(9)]
d = dict(zip(items, [i + ' description.' for i in items]))

root = Tk()
frame = ttk.Frame(root, padding=8)

cb_val = StringVar()
cb_val.set('Item 1')
cb = ttk.Combobox(frame, textvariable=cb_val, height=4)
cb['values'] = sorted(d.keys())

statusmsg = StringVar()
status = ttk.Label(frame, textvariable=statusmsg, relief='solid')

frame.grid()
cb.grid()
status.grid(pady=(80, 0), sticky='SWE')

cb.bind('<<ComboboxSelected>>',
        lambda e: statusmsg.set(d[sorted(d.keys())[int(cb.current())]]))

root.mainloop()

screenshot

So I bind <ComboboxSelected> event to extract selected combobox item by using current() method, then use dictionary lookup to print item description in made statusbar.

This is not bad, but I would like to bind on "hover item" event if possible, and extract the value of currently hovered item from combobox dropdown menu (or as in example screenshot I would like to get "Item 3 description." in statusbar)

As I can't find any documentation about such event, or another approach I thought to ask this here.

1

There are 1 best solutions below

0
On

Here is my brief example

from tkinter import *
from tkinter import ttk


def enviar():
    print(samples.get())

root = Tk()





samples = StringVar()

a = ttk.Combobox(root,textvariable=samples)

a['values']=['San Salvador','La Union','San Marcos','El Puerto']
a.current(0)
a.grid(row=0,column=0)


Button(root,text='enviar',command=enviar).grid(row=0,column=1)
Label(root,text='Ha seleccionado: ',font=('Verdana',12)).grid(row=1,column=0)
Label(root,textvariable=samples).grid(row=1,column=1,sticky=E)




root.mainloop()