python3华丽gui_Python3.7 - tkinter Gui 03 Options的用法

'''三种Options的方式'''

Label(self,text="抗战疫情",width=20,height=2,bg="black",fg="white")

以上这种其实是对参数中,**kw的处理;

self.btn01["bg"]="red"

self.btn01.config(fg="red",bg="blue")

以上这种是cnf={}使用

以上几种传参后,都是调用同一个方法进行合并(可以查看源码):

if kw:

cnf = _cnfmerge((cnf, kw))

总共有这么多Options

Construct a label widget with the parent MASTER.

STANDARD OPTIONS

activebackground, activeforeground, anchor,

background, bitmap, borderwidth, cursor,

disabledforeground, font, foreground,

highlightbackground, highlightcolor,

highlightthickness, image, justify,

padx, pady, relief, takefocus, text,

textvariable, underline, wraplength

WIDGET-SPECIFIC OPTIONS

height, state, width

以下是今天的代码:

from tkinter import *

from tkinter import messagebox

'''三种Options的方式'''

#Label(self,text="抗战疫情",width=20,height=2,bg="black",fg="white")

#self.btn01["command"] = self.songhua

#self.btn01.config(fg="red",bg="blue")

#总共有这么多Options

"""Construct a label widget with the parent MASTER.

STANDARD OPTIONS

activebackground, activeforeground, anchor,

background, bitmap, borderwidth, cursor,

disabledforeground, font, foreground,

highlightbackground, highlightcolor,

highlightthickness, image, justify,

padx, pady, relief, takefocus, text,

textvariable, underline, wraplength

WIDGET-SPECIFIC OPTIONS

height, state, width

"""

#认识传参的办法,可以有cnf={}, **kw

#cnf={},这种方式就是可以将

class Application(Frame):

"""一个经典的GUI程序类的写法"""

def __init__(self,master=None):

super().__init__(master) # super()代表的是父类的定义 ,而不是父类的对像

self.master = master

self.pack()

self.createWidget()

def createWidget(self):

#显示图像

global photo #定义为全局变量

photo = PhotoImage(file="img/aa.gif")

self.label03 =Label(self,image=photo)

self.label03.pack()

self.label01 = Label(self)

self.label01 = Label(self,text="字体颜色",width=20,height=2,bg="black",fg="white")

self.label01.pack()

#设成全局变量

global v1

v1= StringVar()

self.entry01 = Entry(self,textvariable=v1)

self.entry01.pack()

v1.set("black")

"""创建组件"""

self.btn01 = Button(self,text="点击送花,变色")

self.btn01["command"] = self.songhua

self.btn01.pack()

self.btnQuit=Button(self,text="退出",command=root.destroy)

self.btnQuit.pack()

def songhua(self):

messagebox.showinfo("送花","送你99朵花")

self.btn01.config(fg=v1.get(),bg="blue")

if __name__=='__main__':

root = Tk()

root.geometry("400x400+200+300")

root.title("一个经典的GUI程序类测试")

app = Application(master=root)

root.mainloop()

以下是今天代码的效果:

image.png

然后“点击后”

image.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值