当tkinter打开窗口时,Python按钮自动触发。

问题描述 投票:0回答:1

我有python tkinter代码,使用一个按钮来处理数据,但当我打开窗口时,不按按钮就会立即发送值。

apply_button = Button(
    settings_window,
    text="Apply",
    command=process(
        value1.get(),
        value2.get(),
        value3.get(),
        value4.get(),
    ),
)

apply_button.pack()
python tkinter
1个回答
0
投票

貌似是Tkinter。你可以使用 command=lambda: 函数,当你想把参数传递给回调函数时。

代码:Lambda函数的解释:当你想把参数传递给回调函数时,你可以使用这个函数。

apply_button = Button(settings_window, text="Apply", command=lambda: process(value1.get(), value2.get(), value3.get(), value4.get()))
apply_button.pack()

lambda函数的解释。http:/zetcode.comythonlambda#:~:text=Python%20lambda%20with%20Tkinter,function%20for%20the%20command%20parameter.&text=We%20there%20buttons%20that,data%20to%20the%20callback%20function。.

© www.soinside.com 2019 - 2024. All rights reserved.