0

I'm getting a Button instance that has no __call__ method. I have checked and tried everything (at least I think so). Could someone explain why this occurs?

#! 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()

I am new to Python, but this has been bothering me for few days.

# 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 Answer 1

1

You're first defining the method selective_copy, but then overwrite it by defining a new Button with the same name. Make sure you're using different variable names for different objects.

You're getting the exception because a Button object cannot be called like a function.

Sign up to request clarification or add additional context in comments.

1 Comment

And this happens all the time. When Im creating post in Stack, you guys see little mistake, that i dont. Thanks a lot, now it works :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.