天下程序员首页cx06.com
管理 |  登录 |  注册
Button组件添加,文字与图片(同label)
更新于:2024-07-29

Button和label基本一模一样

属性参数基本一个样,唯一就是button有边框,属于按钮

Button用处:

1、提交按钮

2、点击添加动作

上代码(同label)

from tkinter import *
import sys
root=Tk()
root.title("第一个tk程序")
root.geometry("500x300+100+200")

label01=Button(root,text="天下程序员01",width=10,height=2,
              bg="black",fg="white")
label02=Button(root,text="天下程序员02",width=15,height=2,
              bg="black",fg="white",font=("黑体",30))
photo=PhotoImage(file=sys.path[0]+"/logo.png")
label03=Button(root,image=photo,width=190,height=200,
              bg="black",fg="white")

label01.pack()
label02.pack()
label03.pack()


root.mainloop()
天下程序员 www.cx06.com 程序员的网上家园!
作者微信:13126507001