0

I'm not sure if I am blind or stupid or what but I keep getting the error for

done_button = tkinter.Button(window2, text="Done!", command=add_pass(platform,phone,email,user,password))

Error:

Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "C:\Users\Admin\Desktop\GUI\main.py", line 37, in add
    done_button = tkinter.Button(window2, text="Done!", command=add_pass(platform,phone,email,user,password))
TypeError: 'Button' object is not callable

I'm not sure what to do here or what to try but I feel like I hit a dead end.

Code:

def add():
    window2 = tkinter.Tk()
    window2.title("Chase's Password Manager")
    plat_label = tkinter.Label(window2,text="Platform:")
    platform = tkinter.Entry(window2)
    phone_label = tkinter.Label(window2,text="Phone:")
    phone = tkinter.Entry(window2)
    email_label = tkinter.Label(window2,text="Email:")
    email = tkinter.Entry(window2)
    name_label = tkinter.Label(window2,text="Name:")
    user = tkinter.Entry(window2)
    pass_label = tkinter.Label(window2,text="Password:")
    password = tkinter.Entry(window2)
    done_button = tkinter.Button(window2, text="Done!", command=add_pass(platform,phone,email,user,password))
    plat_label.pack()
    platform.pack()
    phone_label.pack()
    phone.pack()
    email_label.pack()
    email.pack()
    name_label.pack()
    user.pack()
    pass_label.pack()
    password.pack()
    done_button.pack()

If you want the definition of "add_pass", here it is.

def add_pass(platform, phone, email, user, password):
  with open('passwords.txt', 'w') as f:
    f.write(f"{platform} | {phone} | {email} | {user} | " + fernet.encrypt(password.encode()).decode() + "\n")
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
  • Does this answer your question? [Why is the command bound to a Button or event executed when declared?](https://stackoverflow.com/questions/5767228/why-is-the-command-bound-to-a-button-or-event-executed-when-declared) – Delrius Euphoria May 17 '22 at 04:21
  • It seems to be implying that `add_pass` is set to a button. Right before you create `done_button` add `print(add_pass)` to see what it is. Regardless, `command=add_pass(...)` will _immediately_ run `add_pass` and pass the result to the `command` attribute. – Bryan Oakley May 17 '22 at 04:21
  • Also you pass those `Entry` widgets instead of their contents to `add_pass()`. – acw1668 May 17 '22 at 04:48
  • I did `print(add_pass)` and `print(done_button)` after the done_button definition and they return `.!button` and `.!button2`. The button shows up no that I removed the (platform,phone,email,user,password) feilds, but it won't work now. It is functionless. – Chase Blackburn May 17 '22 at 04:54
  • So, that's telling you that `add_pass` is a button, not a function. So, when you do `command=add_pass(...)`, you are trying to call a Button object as if it was a function. It's not a function and is not callable, which is what the error is saying. – Bryan Oakley May 17 '22 at 05:15
  • It also appears that you're probably creating more than one instance of `Tk`, which is not how tkinter is designed to work. If you need multiple windows, the second and subsequent windows should be instance of `Toplevel`. – Bryan Oakley May 17 '22 at 05:17

0 Answers0