仅使用多个内容填充列表框

时间:2018-04-12 11:42:22

标签: python tkinter listbox

我希望let target = document.createElement('div'); let source = document.getElementById(this.parentFormId); // change this! source.parentNode.insertBefore(target,source); source.childNodes.forEach(node => { node.parentNode.removeChild(node); target.appendChild(node);}); source.parentNode.removeChild(source); target.id = this.parentFormId; tkinter Listbox一起弹出tuple如果内容存在多个,则只应插入一个内容。在此网站上搜索但未得到解决该问题的答案。

from tkinter import *


rows = (('python', 'kivy'), ('python', 'tkinter'),("python","wxpython",32),
('PHP', 'bootstrap'),('html', 'ajax'),('html', 'css'), ('python', 'tkinter'))

root = Tk()

l = Listbox(root)

for row in rows:
    if row[0] not in rows:
        l.insert(END, row[0])
l.pack()

root.mainloop()

1 个答案:

答案 0 :(得分:1)

根据 @ fhdrsdg 的评论,您将了解如何实现结果。在set之后,您将使用loop获取值要在unique中插入变量Listbox

from tkinter import *


rows = (('python', 'kivy'), ('python', 'tkinter'),("python","wxpython",32),
('PHP', 'bootstrap'),('html', 'ajax'),('html', 'css') )

root = Tk()

l = Listbox(root)

unique =  set([row[0] for row in rows])
for x in unique:
    l.insert(END, x)

l.pack()

root.mainloop()