-- Basic Widget 基础小组件
——————— Button————————————
定义:
按钮往往并不包含文字图片内容
大多时候意味着要用户去点击它
是一种交互工具
_______________________________________
使用:
b= ttk.Button(root, text, command)
b.pack()
_______________________________________
实例:
import tkinter as tk
def write_slogan():
print("Tkinter is easy to use!")
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
button.pack(side=tk.LEFT)
slogan = tk.Button(frame,
text="Hello",
command=write_slogan)
slogan.pack(side=tk.LEFT)
root.mainloop()

—————————————————————————
更改:
如果想更改设置:
label.config( arg = )
—————————————————————————
More:
b.invoke() # 在command line 模拟 点击 button
b.state(['disabled']) # button会变灰 无法使用
instate(state) # check if is the state

本文介绍了Tkinter库中的基础组件Button,包括定义、使用方法、实例展示以及如何更改按钮状态。通过b=ttk.Button(root, text, command)创建按钮,并用b.pack()布局。可以使用b.invoke()模拟点击,或通过b.state(['disabled'])使按钮禁用。"
121464522,8335155,Python装饰器详解与应用,"['Python', '函数装饰器', '编程概念', '代码优化', '函数封装']
1031

被折叠的 条评论
为什么被折叠?



