creating a new line on a textbox in tkinter

旧巷老猫 提交于 2020-07-20 21:02:05

问题


I have imported a list of names from a csv file and want to print each name a new line, how would i go about this as the program i have wrote prints it all on one line?

import csv
from tkinter import *
master=Tk()

file=open('Book1.csv')
qwerty=csv.reader(file)

people=[]
for column in qwerty:
     people.append(column[0:7])

namelbl=Label(text='Name').grid(column=1,row=1)
namebox=Text(master,width=10)
namebox.grid(column=1,row=2)
namesList = [x[0] for x in people]
for names in sorted(namesList):
   namebox.insert(END, names)
   print(names)

master.mainloop()

apology's about the poor coding i'm new. Any help would be appreciated thanks


回答1:


You have just to add \n :

namebox.insert(END, names + '\n')


来源:https://stackoverflow.com/questions/35577359/creating-a-new-line-on-a-textbox-in-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!