如何获得return self.func(* args)在Tkinter Python中工作?

问题描述 投票:0回答:1

我刚刚开始了我的第一个Python项目(很抱歉,如果我刚开始这是一个愚蠢的问题,并正在使用Tkinter接口。我似乎继续收到此提示:

Tkinter回调中的异常追溯(最近一次通话):在____call____中的文件1883行中的文件“ D:\ Apps \ Python \ lib \ tkinter__init __。py”返回self.func(* args)文件“ c:/Users/noahc/Documents/Programming/AppLauncher/AppLauncher.py”,第62行,在resetList = tk.Button(root,text =“ Reset”,padx = 10,pady = 5,fg =“ white”,bg =“#263D42”,command = lambda:[removeSave(),resetList()])TypeError:“按钮”对象不可调用

我提供了以下代码:

#########################
# CREATED BY NOZZYPOZZY #
#########################
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():
    for widget in frame.winfo_children():
        widget.destroy()

def removeSave():
    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=lambda:[removeSave(),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 + ',')

谢谢,nozzypozzy

python tkinter tkinter-canvas
1个回答
2
投票

您的函数resetList与您的Button变量共享一个名称。它会尝试调用自己而不是您的函数。

© www.soinside.com 2019 - 2024. All rights reserved.