python-tkinter-Button

from tkinter import *
from tkinter import font
class AA:
	def __init__(self):
		window=Tk()
		button=Button(window)
		button.pack()
		
		#文本设置(text、textvariabl,underline,wraplength)
		#underline用于指定文本位置画下划线
		#文本方向设置(anchor、justify、padx、pady)
		# anchor用于调整文本(图像)位置(选项为 n,ne,e,se,s,sw,w,nw,center),justify用于调整多行文本(选项为LEFT,RIGHT,CENTER),padx和pady分别用于设定文本(图像)与边框的水平和垂直距离
		#图像设置(bitmap、image)
		picture = PhotoImage(file = "C:\\Users\\zk\\Pictures\\pict.gif")
		#PhotoImage仅支持gif、pgm和ppm格式的文件
		button.config(compound=TOP,image=picture,text="This is a Button,\n Please Click It!",underline=10,anchor="nw",justify=RIGHT,padx=25,pady=25)
		
		# 注:compound控制文本和图像的组合形式(以图片为对象),BOTTOM, LEFT, RIGHT, TOP
		
		#字体设置(font)
		fontset=font.Font(family="Helvetica",size=40,weight="bold")
		button.config(font=fontset)
		
		#按钮颜色设置(bg、fg、activebackground、activeforeground、disabledforeground)
		button.config(bg="blue",fg="white",activebackground="white",activeforeground="red",disabledforeground="gray")
		
		#光标设置(cursor)
		button.config(cursor="plus") #circle 
		
		#尺寸与边框设置:width height borderwidth(bd) relief
		#relief表示边框装饰: flat, groove,ridge, solid,sunken,raised(默认)
		button.config(borderwidth=1,width=500,height=550,relief="solid")
		
		#焦点设置(highlightbackground、highlightcolor、highlightthickness)
		button.config(highlightbackground="green",highlightcolor="black",highlightthickness=20)
		
		#按钮状态(state)-NORMAL, ACTIVE or DISABLED
		button.config(state="normal")
		# 
		#回调command
		button.config(command=self.callback)
		button.invoke() #运行回调函数

		window.mainloop()
	def callback(self):
		print("run callback function!")
	
AA()

# 参考文献:
# http://effbot.org/tkinterbook/button.htm#Tkinter.Button.flash-method
# http://www.360doc.com/showweb/0/0/727828840.aspx

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值