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
總結
以上是生活随笔為你收集整理的python3华丽gui_Python3.7 - tkinter Gui 03 Options的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pandas 按字符串肚脐眼 读取数据_
- 下一篇: python爬虫scrapy安装_零基础