-1

I am programming with tkinter in python 2.7. Used this syntax dozens of times but for some reason in this specific occurrence after I declare the button it calls the function without me pressing it.. here is the code:

def uninstall_win():
    verify = Tk()
    verify.title("Uninstall")
    recheck = make_entry(verify, "Please Re-enter password:", 14, show='*')
    b = Button(verify, borderwidth=4, text="Uninstall", pady=8, command=uninstall(recheck.get()))
    b.pack()
    verify.mainloop()

def make_entry(parent, caption, width=None, **options):
    Label(parent, text=caption).pack(side=TOP)
    entry = Entry(parent, **options)
    if width:
        entry.config(width=width)
    entry.pack(side=TOP, padx=10, fill=BOTH)
    return entry

any insight will be appreciated

Isdj
  • 1,835
  • 1
  • 18
  • 36

2 Answers2

2

You should use lambda when putting a function with arguments in a Button.

b = Button(verify, borderwidth=4, text="Uninstall", pady=8, command=lambda: uninstall(recheck.get()))
kushtrimh
  • 906
  • 2
  • 13
  • 32
0

Becuase you're calling the function instead of passing the function as a callable.

lambda: uninstall(recheck.get())

Passing uninstall(recheck.get()) is setting the command to be what this function returns

Pythonista
  • 11,377
  • 2
  • 31
  • 50