刷题刷出新高度,偷偷领先!偷偷领先!偷偷领先! 关注我们,悄悄成为最优秀的自己!

单选题

import tkinter as tk window = tk.Tk() window.title('Mywindow') window.geometry('200x100') var = tk.StringVar() p= tk.Label(window,textvariable=var,bg='green',font=('Arial', 12),width=15, height=2) p.pack() on_hit = False def hit_me(): ​ global on_hit ​ if on_hit == False: ​ on_hit = True ​ var.set('You hit me!') ​ else: ​ on_hit = False ​ var.set('I Love Python!') b=tk.Button(window, text='点我', width=15, height=2,command=hit_me) b.pack() window.mainloop() 运行如上代码,对按钮点击二次后,在文本框中显示的文字为?( )

A
You hit me!
B
I Love Python!
C
You hit me!
D
I Love Python!
使用微信搜索喵呜刷题,轻松应对考试!

答案:

B

解析:

【喵呜刷题小喵解析】:根据代码,当点击按钮时,会执行hit_me函数。在第一次点击时,on_hit为False,所以将on_hit设置为True,并将var的值设置为'You hit me!'。在第二次点击时,on_hit为True,所以将on_hit设置为False,并将var的值设置为'I Love Python!'。因此,第二次点击后,文本框中显示的文字为'I Love Python!'。所以,正确答案是B。
创作类型:
原创

本文链接:import tkinter as tk window = tk.Tk() window.tit

版权声明:本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明文章出处。

让学习像火箭一样快速,微信扫码,获取考试解析、体验刷题服务,开启你的学习加速器!

分享考题
share