相关疑难解决方法(0)

如何将参数传递给Tkinter中的Button命令?

假设我Button在Python中使用Tkinter进行了以下操作:

import Tkinter as Tk
win = Tk.Toplevel()
frame = Tk.Frame(master=win).grid(row=1, column=1)
button = Tk.Button(master=frame, text='press', command=action)
Run Code Online (Sandbox Code Playgroud)

action当我按下按钮时调用该方法,但是如果我想将一些参数传递给方法action怎么办?

我尝试过以下代码:

button = Tk.Button(master=frame, text='press', command=action(someNumber))
Run Code Online (Sandbox Code Playgroud)

这只是立即调用方法,按下按钮什么都不做.

python arguments tkinter button python-3.x

143
推荐指数
7
解决办法
22万
查看次数

标签 统计

arguments ×1

button ×1

python ×1

python-3.x ×1

tkinter ×1