Python - tkinter - How to call a method in command argument Python - tkinter - How to call a method in command argument tkinter tkinter

Python - tkinter - How to call a method in command argument


The issue comes from how you declare the function export to display the popup, it makes a call to the sample method, which shows the messagebox, that's why you get the pop up too soon.

As a quick fix, replace the export thing by a lambda, directly in the command :

self.button = tk.Button(self,                        text="Login",                        command=lambda : self.sample(username, password))