By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

adding arguments to buttons

P: 6
Using tkinter, how does one add arguments to functions called by buttons? For example I have the line:

Expand|Select|Wrap|Line Numbers
  1.  b = Button(parent, command = self.login) 
but what if self.login has parameters, like requiring a username parameter and password parameter? commands called by buttons, or any tkinter object, don't seem to have any way to send arguments to the functions that they call. I have of course tried:

Expand|Select|Wrap|Line Numbers
  1.  b = Button(parent, command = self.login(username = user, password = password)) 
which does not work.

Thanks ahead of time,
- Adam
Jul 22 '08 #1
Share this Question
Share on Google+
1 Reply

P: 314
You could simply store username and password as members of whatever class is represented by self.

In your function initialization of login, have default values for those parameters, then at the beginning of the function, if the values are default, try the self.username and self.password values.

I do not know of any way to actually pass parameters for a bound function without actually calling it, however.
Jul 22 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.