[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>Button介绍
* Button:Tkinter 按钮组件用于在 Python 应用程序中添加按钮,按钮上可以放上文本或图像,按钮可用于监听用户行为,能够与一个
Python 函数关联,当按钮被按下时,自动调用该函数。
* 本次主要介绍Button控件被点击后text、state属性变化的操作
* text:按钮的文本内容
* state:设置按钮组件状态,可选的有NORMAL、ACTIVE、 DISABLED。默认 NORMAL。
<>示例
* 创建一个可点的按钮 Button(root, text="点我测试", command=click_me) #
按钮文案为:点我测试,点击后调用click_me函数
* 创建一个不可点的按钮 Button(root, text="我不可被点击", state=DISABLED) #
按钮文案为:我不可被点击,状态为不可点状态(置灰)
* 按钮被点击后改变按钮文案,并修改状态为:不可点 from tkinter import * root = Tk() root.geometry(
'200x200') root.resizable(width=False, height=False) root.title('Button Test')
def click_me(): """修改btn控件的text属性以及state""" btn["text"] = "不可点" btn['state'] =
DISABLED Label(root, text="button test").pack() #
btn被点击后,调用click_me函数,将btn文案修改为:不可点,状态修改为DISABLED(置灰状态,不可点击) btn = Button(root,
text="点我测试", command=click_me) btn.pack() btn1 = Button(root, text="我不可被点击",
state=DISABLED) btn1.pack() root.mainloop()
* 按钮被点击后改变按钮文案、状态,执行函数操作后,按钮状态复原 import time from tkinter import * root = Tk()
root.geometry('200x200') root.resizable(width=False, height=False) root.title(
'Button Test') def click_me(): """修改btn控件的text属性以及state,3秒后,恢复原有状态""" btn["text"
] = "不可点" btn['state'] = DISABLED time.sleep(3) btn["text"] = "点我测试" btn['state'
] = NORMAL Label(root, text="button test").pack() #
btn被点击后,调用click_me函数,将btn文案修改为:不可点,状态修改为DISABLED(置灰状态,不可点击),3秒后,恢复原有状态 btn =
Button(root, text="点我测试", command=click_me) btn.pack() btn1 = Button(root, text=
"我不可被点击", state=DISABLED) btn1.pack() root.mainloop()