2017-01-09 76 views
0

我收到沒有__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() 

回答

1

你第一次定義方法selective_copy,但隨後通過使用相同的名稱定義一個新的Button覆蓋。確保你爲不同的對象使用不同的變量名稱。

你會得到例外,因爲Button對象不能被稱爲函數。

+0

這一直髮生。當我在Stack中創建帖子時,你們看到了一點小錯誤,我不會。非常感謝,現在它工作:) –

相關問題