【发布时间】:2015-03-14 00:50:00
【问题描述】:
我正在 Ubuntu 上用TKinter 编写一个 Python 程序来导入和打印
Text 小部件中特定文件夹的文件名。
它只是将文件名添加到Text 中的先前文件名
小部件,但我想先清除它,然后添加一个新的文件名列表。
但我正在努力清除 Text 小部件之前的列表
文件名。
谁能解释一下如何清除Text 小部件?
截图和编码如下:
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()
【问题讨论】:
-
您阅读过文本小部件的任何文档吗?此功能已明确记录在案。你说你很挣扎,你能告诉我们你的尝试吗?
-
你能不能在这里写一个语句来得到我需要的结果
-
@BryanOakley 阅读文档似乎是一个好点,尽管在我看来 tkinter 文档需要某种转移工作。因此,如果您问我:以问题的形式提供更多文档是很好的文档。所以我要 +1。
-
@enthus1ast:我完全同意在线 effbot.org 文档还有很多不足之处。所以我没有使用它,而是经常使用Tkinter 8.5 reference guide,它是由 John Shipman 为 NM Tech 计算机中心编写的。
标签: python tkinter text-widget