文本和按钮 Python Tk GUI

Text and Button Python Tk GUI

如何在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()

据我了解,您想颠倒插入顺序?如果是这样,您可以使用 INSERT:

而不是 1.0
from Tkinter import *

root = Tk()
root.geometry("300x400")

message_list = ["testing on file 0 successfull\n",
                "testing on file 1 successfull\n",
                "testing on file2 successfull\n"]

message_list_idx = 0;


def startProgram():
    global message_list_idx

    if message_list_idx >= len(message_list):
        return
    t3 = message_list[message_list_idx]
    text.insert('1.0', t3)
    message_list_idx += 1


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=startProgram)

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()
button2=Button(root,text="Start Program", width=20,font=12,
               command=startProgram)

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()