How to pass arguments to a Button command in Tkinter?

前端 未结 18 2774
夕颜
夕颜 2020-11-21 07:42

Suppose I have the following Button made with Tkinter in Python:

import Tkinter as Tk
win = Tk.Toplevel()
frame = Tk.Frame(master=win).grid(row=         


        
18条回答
  •  梦如初夏
    2020-11-21 08:07

    I personally prefer to use lambdas in such a scenario, because imo it's clearer and simpler and also doesn't force you to write lots of wrapper methods if you don't have control over the called method, but that's certainly a matter of taste.

    That's how you'd do it with a lambda (note there's also some implementation of currying in the functional module, so you can use that too):

    button = Tk.Button(master=frame, text='press', command= lambda: action(someNumber))
    

提交回复
热议问题