我有一个从ttk组合框继承的类。在用户双击上,我创建了这个组合框,并使用.place()函数
放置了该组合框当我alt标签并从tkinter应用程序中删除焦点时,即使gui的其余部分在屏幕上没有焦点或可见性,组合框值列表仍会显示并可以与之交互。
我正在运行Windows 7。
class ComboBoxPopup(ttk.Combobox):
def __init__(self, gui_parent, item_parent, values, **kw):
''' If relwidth is set, then width is ignored '''
super().__init__(gui_parent, **kw)
self.item_parent = item_parent
self['values'] = values
self['state'] = 'normal'
self['exportselection'] = True
self.focus_force()
self.bind("<Escape>", lambda *ignore: self.destroy())
self.bind("<Return>", lambda *ignore: self.commit_and_exit() )
self.bind("<<ComboboxSelected>>", lambda *ignore: self.commit_and_exit())
编辑:
我正在做更多的试验,似乎我的事件都没有绑定到组合框的下拉列表,而是绑定到了组合框的输入字段。我认为这是我的问题。
答案 0 :(得分:0)
我在组合框上放置的绑定都没有影响下拉列表框(我不知道该下拉列表框的类名)。
但是一旦我将处理程序绑定到所有tkinter小部件类的alt按键上,我就能够在程序的控制下获得下拉列表框并杀死组合框小部件弹出窗口。
self.bind_all("<Alt_L>", self.configurationAbort)
self.bind_all("<Alt_R>", self.configurationAbort)