Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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 无法在tkinter列表框中显示完整项目_Python_Tkinter - Fatal编程技术网

Python 无法在tkinter列表框中显示完整项目

Python 无法在tkinter列表框中显示完整项目,python,tkinter,Python,Tkinter,代码 我希望此代码显示所有项目,如print Station您不应该为文件的每一行创建新的列表框 from tkinter import * top = Tk() lb = Listbox(top, width=100, height=40) lb.pack(side=LEFT, fill=BOTH, expand=1) sb = Scrollbar(top, orient=VERTICAL, command=lb.yview) sb.pack(side=RIGHT, fill=Y) l

代码


我希望此代码显示所有项目,如print Station

您不应该为文件的每一行创建新的列表框

from tkinter import *

top = Tk()

lb = Listbox(top, width=100, height=40)
lb.pack(side=LEFT, fill=BOTH, expand=1)

sb = Scrollbar(top, orient=VERTICAL, command=lb.yview)
sb.pack(side=RIGHT, fill=Y)

lb.config(yscrollcommand=sb.set)

with open('new.txt') as f:
    for line in f:
        lb.insert(END, line)

top.mainloop()
from tkinter import *

top = Tk()

lb = Listbox(top, width=100, height=40)
lb.pack(side=LEFT, fill=BOTH, expand=1)

sb = Scrollbar(top, orient=VERTICAL, command=lb.yview)
sb.pack(side=RIGHT, fill=Y)

lb.config(yscrollcommand=sb.set)

with open('new.txt') as f:
    for line in f:
        lb.insert(END, line)

top.mainloop()