So I made a clear button for my application and it doesn't work because when I press it the save file gets deleted but nothing happens on the app list and when I close the application the save file comes back. I copy and pasted the code here from vs code (The programming software I use).
import tkinter as tk from tkinter import filedialog, Text import os root = tk.Tk() root.title('Application Launcher') apps = [] if os.path.isfile('save.txt'): with open('save.txt', 'r') as f: tempApps = f.read() tempApps = tempApps.split(',') 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 clearApps(): os.remove('save.txt') canvas = tk.Canvas(root, height=500, width=500, bg="#262e2e") canvas.pack() frame = tk.Frame(root, bg="#262e2e") frame.place(relwidth=0.7, relheight=0.7, relx=0.1, rely=0.1) openFile = tk.Button(root, text="Open File", padx=10, pady=5, fg="black", bg="white", command=addApp) openFile.pack() runApps = tk.Button(root, text="Run Apps", padx=10, pady=5, fg="black", bg="white", command= runApps) runApps.pack() clearApps = tk.Button(root, text="Clear", command=clearApps) clearApps.pack(side=tk.LEFT) 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 + ',') https://stackoverflow.com/questions/65930888/my-clear-button-works-but-the-apps-dont-go-away January 28, 2021 at 12:04PM
没有评论:
发表评论