python tkinter简介(5)–按钮控件

看这里<title>

前言


今天心情好 更新吧。
今天讲的是按钮,有了它 你的tkinter一定会更进一步

正文


按钮的创建方法为

name=Button(master,text,command,bg,fg,font,width,height,padx,pady,state,highlightcolor,imgage)

上面的参数的作用如下
(以下示例都包含from tkinter import *)
text: 这是按钮上显示的文本。

button = Button(root, text="Click Me!")

command: 当按钮被点击时执行的函数或方法。

def on_click():
    print("Button clicked!")

button = Button(root, text="Click Me!", command=on_click)

bg (或 background): 按钮的背景颜色。

button = Button(root, text="Click Me!", bg="red")

fg (或 foreground): 按钮上文本的颜色。

button = Button(root, text="Click Me!", fg="white")

font: 按钮上文本的字体。

button = Button(root, text="Click Me!", font=("Helvetica", 16))

width: 按钮的宽度(以字符数为单位)。

button = Button(root, text="Click", width=10)

height: 按钮的高度(以行数为单位)。

button =Button(root, text="Click", height=3)

padxpady: 按钮内部文本与其边界之间的水平和垂直填充。

button = Button(root, text="Click", padx=10, pady=5)

state: 按钮的状态。可以是 NORMAL、DISABLED 或 ACTIVE。有禁用 正常 什么的

button = Button(root, text="Click", state="disabled")

highlightbackground: 当按钮没有焦点时的高亮边框颜色。

button = Button(root, text="Click", highlightbackground="blue")
highlightcolor: 当按钮有焦点时的高亮边框颜色。
python
button = Button(root, text="Click", highlightcolor="green")

image: 在按钮上显示的图像。

from tkinter import PhotoImage

image = PhotoImage(file="pngname.png")
button = Button(root, image=image)

别忘了创建布局 要不然显示不出来 具体看上一篇
今天怎么什么也想不出来啊!算了 就到这里吧

后言

懒得写
上一篇:python tkinter简介(4)–布局管理
下一篇:python tkinter简介(5)–输入框
注意了 c++不出意外的话要开坑了
还有我的bilibili号也要发视频了
here
here
here
here
here
here
here
here

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值