python - 如何删除 Python Tkinter 中的打印文本?
问题描述
我最近一直在开发一个应用程序,但我似乎无法找到如何在使用 Tkinter 界面时单击按钮删除 Python 中的打印文本。我提供了以下代码:
import tkinter as tk
from tkinter import filedialog, Text
import os
root = tk.Tk()
root.title("App Launcher")
root.iconbitmap('C:/Users/noahc/Documents/Programming/AppLauncher/icon.ico')
root.resizable(0,0)
apps = []
if os.path.isfile('save.txt'):
with open('save.txt','r') as f:
tempApps = f.read()
tempApps = tempApps.split(',')
apps = tempApps
apps = [x for x in tempApps if x.strip()]
def addApp():
for widget in frame.winfo_children():
widget.destroy()
filename = filedialog.askopenfilename(initialdir="/", title="Select File", filetypes=(("Executables","*.exe"), ("All Files", "*.*")))\
apps.append(filename)
print(filename)
for app in apps:
label = tk.Label(frame, text=app, bg="gray")
label.pack()
def runApps():
for app in apps:
os.startfile(app)
def resetList():
os.remove("save.txt")
canvas = tk.Canvas(root, height=700, width=700, bg="gray")
canvas.pack()
frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
openFile = tk.Button(root, text="Open File", padx=10, pady=5, fg="white", bg="#263D42", command=addApp)
openFile.pack()
runApps = tk.Button(root, text="Run Apps", padx=10, pady=5, fg="white", bg="#263D42", command=runApps)
runApps.pack()
resetList = tk.Button(root, text="Reset", padx=10, pady=5, fg="white", bg="#263D42", command=resetList)
resetList.pack()
for app in apps:
label = tk.Label(frame, text=app)
label.pack()
root.mainloop()
with open('save.txt', 'w') as f:
for app in apps:
f.write(app + ',')
如果有人能告诉我一种方法来删除打印的文件名,只需单击一个按钮,我将不胜感激
谢谢,
注意
解决方案
下面的代码似乎有效:
def resetList():
os.remove("save.txt")
for widget in frame.winfo_children():
widget.destroy()
我还要非常感谢所有试图提供帮助的人。
推荐阅读
- javascript - 使用 JavaScript 进行 JSON 转换
- python - 如何在 CPython 中将错误消息作为字符串获取
- mongodb - 将 MongoDB 从 2.6 升级到 4.2.6
- corda - 如何在 TokenSDK 中使用 addIssueTokens Utility 方法
- ruby-on-rails - Money-rails 显示金额为数千
- c++ - 当我在 Ubuntu 终端上发送 SIGTERM (Ctrl + C) 时,为什么我的 C++ 代码没有终止?
- javascript - 在 keyup 函数中使用通配符
- nginx - 获取 Web 服务的 kerberos/Windows AD 登录工作的问题
- google-apps-script - 将特定数据从工作表复制到工作表
- javascript - 如何在 Node.js 中使用 Jimp 调整图像大小以进行上传而不刷新