日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發(fā)布時間:2025/3/15 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3华丽gui_Python3.7 - tkinter Gui 03 Options的用法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

'''三種Options的方式'''

Label(self,text="抗戰(zhàn)疫情",width=20,height=2,bg="black",fg="white")

以上這種其實是對參數(shù)中,**kw的處理;

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

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

以上這種是cnf={}使用

以上幾種傳參后,都是調(diào)用同一個方法進行合并(可以查看源碼):

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="抗戰(zhàn)疫情",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):

"""一個經(jīng)典的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")

"""創(chuàng)建組件"""

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("一個經(jīng)典的GUI程序類測試")

app = Application(master=root)

root.mainloop()

以下是今天代碼的效果:

image.png

然后“點擊后”

image.png

總結

以上是生活随笔為你收集整理的python3华丽gui_Python3.7 - tkinter Gui 03 Options的用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。