2017-01-09 13 views
0

Buttonインスタンスに__call__メソッドがありません。私はすべてをチェックして試した(少なくとも私はそうだと思う)。誰かがなぜこれが起こるのか説明できますか?tkinter Buttonインスタンスに呼び出しメソッドがありません

#! 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で投稿を作成するとき、皆さんはほとんど間違いを見ません。私はそれをしません。ありがとう、今は動作:) –

関連する問題