adding arguments to buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdamGr
    New Member
    • Jun 2008
    • 6

    adding arguments to buttons

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

    Code:
     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:

    Code:
     b = Button(parent, command = self.login(username = user, password = password))
    which does not work.

    Thanks ahead of time,
    - Adam
  • jlm699
    Contributor
    • Jul 2007
    • 314

    #2
    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.

    Comment

    Working...