Tkinter的按钮实例没有调用方法
问题描述:
我收到没有__call__方法的按钮实例。我已经检查并尝试了一切(至少我是这么认为的)。有人可以解释为什么发生这种情况?Tkinter的按钮实例没有调用方法
#! python2
#find_file.py - program will find every file with file format
#which user will input and then will copy all files to new folder
from Tkinter import *
import tkMessageBox, os, shutil
def launch_start():
#Input folder path to check
check_folder_path = cfp_string.get()
selective_copy(check_folder_path)
#screen buttons
def selective_copy(folder):
#walk through folder tree
for folderName, subfolders, filenames in os.walk(folder):
#print("Enter the new folder path: ")
new_folder_path = nfp_string.get()
os.mkdir(new_folder_path)
#print("Enter file extension:")
file_extension = fe_string.get()
for filename in filenames:
#for file nam need to add full path
full_file_name = os.path.join(folder, filename)
if filename.endswith(file_extension):
#print("This is png file in this folder.")
shutil.copy(full_file_name, new_folder_path)
#print(filename, "\n")
break
#main window
window = Tk()
window.title("_Find your files_")
window.geometry("580x210")
frame = Frame(window)
frame.pack()
我是Python的新手,但这已经困扰了我好几天。
# first text and entry box
fe_string = StringVar()
file_extension_message = Label(frame, text="Enter file extension:", fg="black")
file_extension_message.grid(row=0, column=0,padx=20, pady=10)
file_extension_E = Entry(frame, textvariable=fe_string)
file_extension_E.grid(row=0, column=1, padx=20, pady=20)
cfp_string = StringVar()
check_folder_message = Label(frame, text="Enter the path,\nwhere you want to check for files:", fg="black")
check_folder_message.grid(row=50, column=0, padx=20, pady=20)
check_folder_path_E = Entry(frame, textvariable=cfp_string)
check_folder_path_E.grid(row=50, column=1, padx=20, pady=20)
nfp_string = StringVar()
new_folder_message = Label(frame, text="Enter the path of new folder, \nwhere you want to collect your files:", fg="black")
new_folder_message.grid(row=100, column=0, padx=20, pady=20)
new_folder_path_E = Entry(frame, textvariable=nfp_string)
new_folder_path_E.grid(row=100, column=1, padx=20, pady=20)
#Button
selective_copy = Button(frame, text="Find and copy files", command=launch_start, width=20, height=1)
selective_copy.grid(row=100, column=2, padx=20, pady=20)
window.mainloop()
答
你第一次定义方法selective_copy
,但随后通过使用相同的名称定义一个新的Button
覆盖。确保你为不同的对象使用不同的变量名称。
你会得到例外,因为Button
对象不能被称为函数。
这一直发生。当我在Stack中创建帖子时,你们看到了一点小错误,我不会。非常感谢,现在它工作:) –