关于Python Tkinter中Button组件的带参事件绑定,下列写法正确的是?

cj196586 单选题 共 个子题

现有如下Python代码片段,需要实现点击Tkinter按钮时调用带参数的show_message函数并打印指定内容:

import tkinter as tk
root = tk.Tk()
def show_message(msg):
    print(f"按钮点击提示:{msg}")

# 待完成Button组件的事件绑定

下列四个选项中,哪一个可以正确完成该绑定需求?

A

btn = tk.Button(root, text="测试按钮", command=show_message("Hello Tkinter"))

B

btn = tk.Button(root, text="测试按钮", command=lambda: show_message("Hello Tkinter"))

C

btn = tk.Button(root, text="测试按钮", command=show_message)

D

btn = tk.Button(root, text="测试按钮", bind="<Button-1>", show_message("Hello Tkinter"))

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧