Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用<&书信电报;ListboxSelect>&燃气轮机;具有多个列表框_Python_Python 3.x_Tkinter_Pycharm - Fatal编程技术网

Python 使用<&书信电报;ListboxSelect>&燃气轮机;具有多个列表框

Python 使用<&书信电报;ListboxSelect>&燃气轮机;具有多个列表框,python,python-3.x,tkinter,pycharm,Python,Python 3.x,Tkinter,Pycharm,我试图使用多个列表框作为显示信息树的一种方式 # dictionary: {str : [str]} dict_ = {some_class.get_dictionary()} dict_keys = list[dict.keys()] dict_keys.sort() def selected_item(val): list_box_2.delete(0, END) sender = val.widget index = sender.curselection()

我试图使用多个列表框作为显示信息树的一种方式

# dictionary: {str : [str]}
dict_ = {some_class.get_dictionary()}
dict_keys = list[dict.keys()]
dict_keys.sort()

def selected_item(val):
    list_box_2.delete(0, END)

    sender = val.widget
    index = sender.curselection()
    value = sender.get(index)

    for thing in dict[value]:
        list_box_2.insert(END, thing)

list_box_1 = Listbox(display_frame, selectmode=SINGLE)
for item in dict_keys:
    list_box_1.insert(END, item)
list_box_1.bind("<<ListboxSelect>>", selected_item)
list_box_1.grid(sticky=W+E+N+S)

def display_selected(val):
    sender = val.widget
    index = sender.curselection()
    value = sender.get(index)
    # here I actually call methods from value, value is a class.
    # this in turn should populate a third list_box but I can't get there.
    print(value)

list_box_2 = Listbox(display_frame, selectmode=SINGLE)
list_box_2.bind("<<ListboxSelect>>", display_selected)
list_box_2.grid(column=0, row=1, sticky=W+E)
#字典:{str:[str]}
dict_uu={some_class.get_dictionary()}
dict_keys=列表[dict.keys()]
dict_keys.sort()
def所选项目(val):
列表框2.删除(0,结束)
sender=val.widget
index=sender.curselection()
value=sender.get(索引)
对于dict[值]中的事物:
列表框2.插入(结束,事物)
列表框1=列表框(显示框,选择模式=单一)
对于dict_键中的项目:
列表框1.插入(结束,项目)
列表框1.bind(“,选定项)
列表框1.网格(粘性=W+E+N+S)
已选择def显示(val):
sender=val.widget
index=sender.curselection()
value=sender.get(索引)
#这里我实际上是从value调用方法,value是一个类。
#这反过来应该填充第三个列表框,但我无法到达那里。
打印(值)
列表框2=列表框(显示框,选择模式=单个)
列表框2.bind(“,显示选中)
列表框2.网格(列=0,行=1,粘性=W+E)
List_box_1按预期工作:它显示字典键,当用户单击其中一个项目时,它会在所选键处用字典的内容填充List_box_2。但是,当我单击列表框2中的项目时,它调用
selected\u item()
,而不是
display\u selected
(或者两者都调用,很难说),但这会导致列表框2中的所有内容被删除(因为
列表框2.delete(0,END)
)。我相信这是因为绑定到
”,但我不确定

有什么方法可以实现我想要的功能吗?我环顾四周,绞尽脑汁,但找不到任何有关这方面的信息


谢谢

您应该始终在Tkinter列表框中包含
exportselection=0
选项,尤其是当您同时在屏幕上显示多个选项时。没有这个选项的默认模式是一种奇怪的模式,在这种模式下,列表选择绑定到系统剪贴板;在多个列表中同时进行选择根本不可能存在(而且你正在破坏用户自己可能放在剪贴板中的任何内容)。

哇,太棒了!谢谢你的帮助!现在很有魅力。我将确保使用exportselection=0。顺便说一句,将列表框绑定到系统剪贴板是谁的主意?