+-
如何清除/删除Tkinter Text小部件的内容?
我正在Ubuntu上的TKinter中编写一个 Python程序来导入和打印
文本小部件中特定文件夹中的文件名称.
它只是将文件名添加到文本中的前一个文件名中
小部件,但我想首先清除它,然后添加一个新的文件名列表.
但我正在努力清除Text小部件的上一个列表
文件名.

有人可以解释如何清除文本小部件吗?

屏幕截图和编码如下:

screenshot showing text widget with contents

import os
from Tkinter import *

def viewFile():
    path = os.path.expanduser("~/python")
    for f in os.listdir(path):
        tex.insert(END, f + "\n")

if __name__ == '__main__':
    root = Tk()

    step= root.attributes('-fullscreen', True)
    step = LabelFrame(root, text="FILE MANAGER", font="Arial 20 bold italic")
    step.grid(row=0, columnspan=7, sticky='W', padx=100, pady=5, ipadx=130, ipady=25)

    Button(step, text="File View", font="Arial 8 bold italic", activebackground=
           "turquoise", width=30, height=5, command=viewFile).grid(row=1, column=2)
    Button(step, text="Quit", font="Arial 8 bold italic", activebackground=
           "turquoise", width=20, height=5, command=root.quit).grid(row=1, column=5)

    tex = Text(master=root)
    scr=Scrollbar(root, orient=VERTICAL, command=tex.yview)
    scr.grid(row=2, column=2, rowspan=15, columnspan=1, sticky=NS)
    tex.grid(row=2, column=1, sticky=W)
    tex.config(yscrollcommand=scr.set, font=('Arial', 8, 'bold', 'italic'))

    root.mainloop()
最佳答案
我只是添加了“1.0”来检查我的身体并开始工作

tex.delete('1.0', END)

你也可以试试这个

点击查看更多相关文章

转载注明原文:如何清除/删除Tkinter Text小部件的内容? - 乐贴网