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
python-tkinter-Button
最新推荐文章于 2024-02-24 13:56:18 发布