当单击表单上的其他位置时,tkinter 列表框失去了选择
tkinter Listbox loses its selection when clicking elsewhere on the form
当 tkinter 表单包含列表框和其他小部件时,单击其他小部件(尤其是拖动鼠标时)会导致列表框失去其选择——这意味着 was/were selected/highlighted 在 lisbox 中变为未选中状态。
我在网上看到一两个地方讨论过这个问题,提出了这个解决方案:将列表框 exportselection
的值设置为 False
:
lb = Listbox(leftPane, width=24, height=4, selectmode=EXTENDED)
lb.exportselection = False
但这在我的应用程序中根本不起作用。 (在 Tkinter 8.5 和 Tkinter 8.6.1、Python 3.3、Python 3.4 上试过...在各种 Linux 发行版上。这个问题非常稳定,无论应用程序在哪个listobox 是,或者它的部署环境。)
想法?
你做错了。您需要使用config(或配置)方法:
lb.configure(exportselection=False)
当 tkinter 表单包含列表框和其他小部件时,单击其他小部件(尤其是拖动鼠标时)会导致列表框失去其选择——这意味着 was/were selected/highlighted 在 lisbox 中变为未选中状态。
我在网上看到一两个地方讨论过这个问题,提出了这个解决方案:将列表框 exportselection
的值设置为 False
:
lb = Listbox(leftPane, width=24, height=4, selectmode=EXTENDED)
lb.exportselection = False
但这在我的应用程序中根本不起作用。 (在 Tkinter 8.5 和 Tkinter 8.6.1、Python 3.3、Python 3.4 上试过...在各种 Linux 发行版上。这个问题非常稳定,无论应用程序在哪个listobox 是,或者它的部署环境。)
想法?
你做错了。您需要使用config(或配置)方法:
lb.configure(exportselection=False)