ttk 组合框列表值在 alt-tabbing 后保持打开状态
ttk combobox list values remain open after alt-tabbing
我有一个 class 继承自 ttk 组合框。在用户双击时,我创建了这个组合框并使用 .place() 函数放置它
当我使用 alt-tab 键并从我的 tkinter 应用程序中移除焦点时,组合框值列表仍然显示并且可以与之交互,即使 gui 的其余部分在我的屏幕上没有焦点或可见性。
我是运行windows7.
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())
编辑:
我正在对此进行更多试验,似乎 none 我的事件绑定到组合框的下拉列表,仅绑定到组合框的输入字段。我认为这是我的问题。
None 我放置在组合框上的绑定影响了下拉列表框(我不知道该下拉列表框的 class 名称)。
但是一旦我将处理程序绑定到所有 tkinter 小部件 classes 的 alt 按键,我就能够在程序的控制下获得下拉列表框并终止组合框小部件弹出窗口。
self.bind_all("<Alt_L>", self.configurationAbort)
self.bind_all("<Alt_R>", self.configurationAbort)
我有一个 class 继承自 ttk 组合框。在用户双击时,我创建了这个组合框并使用 .place() 函数放置它
当我使用 alt-tab 键并从我的 tkinter 应用程序中移除焦点时,组合框值列表仍然显示并且可以与之交互,即使 gui 的其余部分在我的屏幕上没有焦点或可见性。
我是运行windows7.
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())
编辑:
我正在对此进行更多试验,似乎 none 我的事件绑定到组合框的下拉列表,仅绑定到组合框的输入字段。我认为这是我的问题。
None 我放置在组合框上的绑定影响了下拉列表框(我不知道该下拉列表框的 class 名称)。
但是一旦我将处理程序绑定到所有 tkinter 小部件 classes 的 alt 按键,我就能够在程序的控制下获得下拉列表框并终止组合框小部件弹出窗口。
self.bind_all("<Alt_L>", self.configurationAbort)
self.bind_all("<Alt_R>", self.configurationAbort)