简体   繁体   English

在列表中分隔单词Tkinter Listbox Python

[英]Separating Words in a List Tkinter Listbox Python

In my source code for a project I am running I have a process that produces a list of strings. 在我正在运行的项目的源代码中,我有一个生成字符串列表的进程。 I am trying to put this list into a Tkinter listbox for easy sorting, but when I do the list is all inserted into one line and I can't find a way to separate the individual words into a different line on the listbox. 我试图将此列表放入Tkinter列表框以便于排序,但是当我这样做时,列表全部插入到一行中,我找不到将单个单词分隔到列表框中的不同行的方法。 Any ideas I am open to anything. 我对任何事情都持开放态度。 Below I have attach an example of what I am trying to do: 下面我附上一个我想要做的例子:

from Tkinter import *

app = Tk()
app.geomtery("500x700")
app.title("ListBox")

names = ["Greg", "Earl", "Harry", "Bob"]

box = Listbox(app)
# Right here is where I am stuck
box.insert(END, names)
box.pack()

app.mainloop() 

This is how you could do it: 这是你如何做到的:

from Tkinter import *

app = Tk()
app.geometry("500x700")
app.title("ListBox")

names = ["Greg", "Earl", "Harry", "Bob"]

box = Listbox(app)
# Right here is where I am stuck
for name in names:
    box.insert(END, name)

box.pack()
app.mainloop()

very esay in python, no ?: just add the item and not the list 非常esay在python中,没有?:只是添加项而不是列表

# Right here is where I am stuck
for i in names:
    box.insert(END, i)

and

app.geometry("500x700")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM