【发布时间】:2015-04-24 07:03:29
【问题描述】:
如何在 Python Tk GUI 中按下按钮后将插入的文本一一显示?我成功运行了以下程序,但它在最后一个文本的末尾将所有插入的文本一起填充。我想按插入文本的顺序相应地更新文本字段。任何人都可以帮忙吗?谢谢。
from Tkinter import *
root = Tk()
root.geometry("300x400")
def startProgram(shapefile_path):
t1 = "testing on file 0 successfull\n"
text.insert('1.0', t1)
t2 = "testing on file 1 successfull\n"
text.insert('1.0', t2)
t3 = "testing on file2 successfull\n"
text.insert('1.0', t3)
text = Text(root, height=8, width=25)
text.grid(row=10, column=0, padx=20, pady=5)
label = Label(root, text="Status",font=12)
label.grid(row=9, column=0, padx=5, pady=5)
button2=Button(root,text="Start Program", width=20,font=12,command=lambda: startProgram(0))
button2.grid(row=7, column=0, padx=20, pady=10)
button3=Button(root, text='Exit Program', width=20,font=12,command=root.destroy)
button3.grid(row=8, column=0,padx=20, pady=10)
root.mainloop()
【问题讨论】:
标签: python button text tkinter