How to select at the same time from two Listbox?(如何从两个Listbox中同时选择?)
问题描述
from Tkinter import *
master = Tk()
listbox = Listbox(master)
listbox.pack()
listbox.insert(END, "a list entry")
for item in ["one", "two", "three", "four"]:
listbox.insert(END, item)
listbox2 = Listbox(master)
listbox2.pack()
listbox2.insert(END, "a list entry")
for item in ["one", "two", "three", "four"]:
listbox2.insert(END, item)
master.mainloop()
上面的代码创建了一个带有两个列表框的 tkinter
窗口.但是,如果您想从两者中检索值,则会出现问题,因为一旦您在其中一个中选择了一个值,它就会取消选择您在另一个中选择的任何内容.
The code above creates a tkinter
window with two listboxes. But there's a problem if you want to retrieve the values from both because, as soon as you select a value in one, it deselects whatever you selected in the other.
这只是开发人员必须忍受的限制吗?
Is this just a limitation developers have to live with?
推荐答案
简答:将所有列表框小部件的 exportselection
属性的值设置为 False 或零.
Short answer: set the value of the exportselection
attribute of all listbox widgets to False or zero.
来自 a列表框小部件的pythonware概述:
默认情况下,选择导出X选择机制.如果你有多个列表框屏幕,这真的把事情搞砸了对于可怜的用户.如果他选择一个列表框中的东西,然后在另一个中选择某些东西,原始选择被清除.它是通常禁用此功能是个好主意这种情况下的机制.在里面下面的例子,三个列表框是在同一个对话框中使用:
By default, the selection is exported to the X selection mechanism. If you have more than one listbox on the screen, this really messes things up for the poor user. If he selects something in one listbox, and then selects something in another, the original selection is cleared. It is usually a good idea to disable this mechanism in such cases. In the following example, three listboxes are used in the same dialog:
b1 = Listbox(exportselection=0)
for item in families:
b1.insert(END, item)
b2 = Listbox(exportselection=0)
for item in fonts:
b2.insert(END, item)
b3 = Listbox(exportselection=0)
for item in styles:
b3.insert(END, item)
tk 小部件的权威文档基于 Tcl 语言而不是 python,但很容易翻译成 python.exportselection
属性可以在 标准选项手册页.
The definitive documentation for tk widgets is based on the Tcl language rather than python, but it is easy to translate to python. The exportselection
attribute can be found on the standard options manual page.
这篇关于如何从两个Listbox中同时选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从两个Listbox中同时选择?


基础教程推荐
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01