最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python中按鈕(BUTTON)樣式屬性及說(shuō)明

 更新時(shí)間:2025年01月23日 10:08:35   作者:SAPmatinal  
文章介紹了Python中tkinter庫(kù)中的Button組件,用于在GUI中添加按鈕,按鈕可以包含文本或圖像,并且可以通過(guò)點(diǎn)擊執(zhí)行特定函數(shù),文章詳細(xì)說(shuō)明了Button組件的構(gòu)造語(yǔ)法和常用參數(shù),并提供了一個(gè)代碼示例

Python按鈕(BUTTON)樣式屬性

Python tkinter 按鈕組件用于tkinter GUI里添加按鈕,按鈕可以添加文本和圖像。

當(dāng)按鈕按下時(shí),可以執(zhí)行指定的函數(shù)。

使用語(yǔ)法

widget = Button( master, parameter=value, ... )
  • master:按鈕控件的父容器
  • parameter:按鈕的參數(shù)
  • value:參數(shù)對(duì)應(yīng)的值

各參數(shù)之間以逗號(hào)分隔。

參數(shù)說(shuō)明

代碼示例

# -*- coding:utf-8 -*-
from tkinter import *
 
 
class buttons:
    def __init__(self):
        root = Tk()
        root.title("按鈕")  # 設(shè)置窗口標(biāo)題
        root.geometry("600x600")  # 設(shè)置窗口大小 注意:是x 不是*
        '''按鈕樣式'''
        # 按鈕文字切換
        self.btsd = Label(root, text='按鈕文字切換:')
        self.bts = Button(root, text='按鈕開始', command=self.Button_text_switch)
        # 按鈕狀態(tài)
        self.button_state = Label(root, text='按鈕狀態(tài):')
        self.disabled_state = Button(root, text='禁用狀態(tài)')
        self.disabled_state.config(state=DISABLED)
        self.usual_status = Button(root, text='普通狀態(tài)')
        self.usual_status.config(state=NORMAL)
        self.active = Button(root, text='活躍狀態(tài)')
        self.active.config(state=ACTIVE)
        # 鼠標(biāo)點(diǎn)擊到按鈕后改變顏色,activebackground='背景色',activeforeground='前景色'
        self.mouse_click_color = Label(root, text='鼠標(biāo)點(diǎn)擊顏色:')
        self.click_background_colour = Button(root, text='背景色', activebackground='blue')
        self.click_foreground_colour = Button(root, text='前景色', activeforeground='blue')
        # 按鈕邊框大小,bd='邊框大小'
        self.button_border_size = Label(root, text='按鈕邊框大?。?)
        self.border = Button(root, text='按鈕邊框', bd=5)
        # 按鈕顏色,bg='背景色', fg='前景色'
        self.the_button_color = Label(root, text='按鈕顏色:')
        self.button_background_colour = Button(root, text='背景色', bg='blue')
        self.button_foreground_colour = Button(root, text='前景色', fg='blue')
        # 按鈕字體格式, font=('字體', 字體大小, 'bold/italic/underline/overstrike')
        self.button_font_format = Label(root, text='按鈕字體格式:')
        self.button_face1 = Button(root, text='軟體雅黑/12/重打印', font=('軟體雅黑', 10, 'overstrike'))
        self.button_face2 = Button(root, text='宋體/12/斜體', font=('宋體', 10, 'italic'))
        self.button_face3 = Button(root, text='黑體/12/加粗', font=('黑體', 10, 'bold'))
        self.button_face4 = Button(root, text='楷體/12/下劃線', font=('楷體', 10, 'underline'))
        # 按鈕高度,height='高度'
        self.button_border_xy = Label(root, text='按鈕邊xy:')
        self.button_height = Button(root, text='按鈕高度', height=2)
        self.button_width = Button(root, text='按鈕寬度', width=16)
        # 按鈕圖片設(shè)置,image=圖片變量。圖片必須以變量的形式賦值給image,圖片必須是gif格式。
        self.button_image_settings = Label(root, text='按鈕圖片設(shè)置:')
        gif = PhotoImage(file="1.gif")
        self.button_image = Button(root, image=gif)
        # 按鈕文字對(duì)齊方式,可選項(xiàng)包括LEFT, RIGHT, CENTER
        self.text_alignment = Label(root, text='文字對(duì)齊方式:')
        self.text_left = Button(root, text='左對(duì)齊\n文字左側(cè)對(duì)齊', justify=LEFT)
        self.text_center = Button(root, text='居中對(duì)齊\n文字居中對(duì)齊', justify=CENTER)
        self.text_tight = Button(root, text='右對(duì)齊\n文字右側(cè)對(duì)齊', justify=RIGHT)
        # 按鈕文字與邊框之間的間距,padx='x軸方向間距大小',pady='y軸間距大小'
        self.text_border_spacing = Label(root, text='文字邊框間距:')
        self.button_padx = Button(root, text='x軸間距', padx=0)
        self.button_pady = Button(root, text='y軸間距', pady=10)
        # 框樣式,設(shè)置控件3D效果,可選的有:FLAT、SUNKEN、RAISED、GROOVE、RIDGE。
        self.box_style = Label(root, text='按鈕框樣式:')
        self.button_relief1 = Button(root, text='邊框平坦', relief=FLAT)
        self.button_relief2 = Button(root, text='邊框凹陷', relief=SUNKEN)
        self.button_relief3 = Button(root, text='邊框凸起', relief=RAISED)
        self.button_relief4 = Button(root, text='邊框壓線', relief=GROOVE)
        self.button_relief5 = Button(root, text='邊框脊線', relief=RIDGE)
        # 按鈕達(dá)到限制字符后換行顯示
        self.Line_shows_state = Label(root, text='文字換行顯示:')
        self.selfLine_shows = Button(root, text='1234567890', wraplength=30)
        # 下劃線。取值就是帶下劃線的字符串索引,為 0 時(shí),第一個(gè)字符帶下劃線,為 1 時(shí),第兩個(gè)字符帶下劃線,以此類推
        self.underline_state = Label(root, text='文字標(biāo)下劃線:')
        self.underline = Button(root, text='12345', underline=2)
 
        '''grid布局'''
        self.btsd.grid(row=1, column=1, sticky='E')
        self.bts.grid(row=1, column=2, sticky='NW')
        self.button_state.grid(row=2, column=1, sticky='E')
        self.disabled_state.grid(row=2, column=2, sticky='NW')
        self.usual_status.grid(row=2, column=3, sticky='NW')
        self.active.grid(row=2, column=4, sticky='NW')
        self.mouse_click_color.grid(row=3, column=1, sticky='E')
        self.click_background_colour.grid(row=3, column=2, sticky='NW')
        self.click_foreground_colour.grid(row=3, column=3, sticky='NW')
        self.button_border_size.grid(row=4, column=1, sticky='E')
        self.border.grid(row=4, column=2, columnspan=3, sticky='NW')
        self.the_button_color.grid(row=5, column=1, sticky='E')
        self.button_background_colour.grid(row=5, column=2, sticky='NW')
        self.button_foreground_colour.grid(row=5, column=3, sticky='NW')
        self.button_font_format.grid(row=6, column=1, sticky='E')
        self.button_face1.grid(row=6, column=2, columnspan=2, sticky='NW')
        self.button_face2.grid(row=6, column=4, columnspan=2, sticky='NW')
        self.button_face3.grid(row=6, column=6, columnspan=2, sticky='NW')
        self.button_face4.grid(row=6, column=8, columnspan=2, sticky='NW')
        self.button_border_xy.grid(row=7, column=1, sticky='E')
        self.button_height.grid(row=7, column=2, sticky='NW')
        self.button_width.grid(row=7, column=3, columnspan=2, sticky='NW')
        self.button_image_settings.grid(row=8, column=1, sticky='E')
        self.button_image.grid(row=8, column=2, columnspan=3, sticky='NW')
        self.text_alignment.grid(row=9, column=1, sticky='E')
        self.text_left.grid(row=9, column=2, columnspan=2, sticky='NW')
        self.text_center.grid(row=9, column=4, columnspan=2, sticky='NW')
        self.text_tight.grid(row=9, column=6, columnspan=2, sticky='NW')
        self.text_border_spacing.grid(row=10, column=1, sticky='E')
        self.button_padx.grid(row=10, column=2, sticky='NW')
        self.button_pady.grid(row=10, column=3, sticky='NW')
        self.box_style.grid(row=11, column=1, sticky='E')
        self.button_relief1.grid(row=11, column=2, sticky='NW')
        self.button_relief2.grid(row=11, column=3, sticky='NW')
        self.button_relief3.grid(row=11, column=4, sticky='NW')
        self.button_relief4.grid(row=11, column=5, sticky='NW')
        self.button_relief5.grid(row=11, column=6, sticky='NW')
        self.Line_shows_state.grid(row=12, column=1, sticky='E')
        self.selfLine_shows.grid(row=12, column=2, sticky='NW')
        self.underline_state.grid(row=13, column=1, sticky='E')
        self.underline.grid(row=13, column=2, sticky='NW')
        root.mainloop()
 
    # 按鈕開關(guān)設(shè)置
    def Button_text_switch(self):
        if self.bts['text'] == '按鈕開始':  # 如果文字是開始,則改為關(guān)閉
            self.bts['text'] = '按鈕關(guān)閉'
            print('按鈕開始')
        else:  # 如果不是開始,則改為開始
            self.bts['text'] = '按鈕開始'
            print('按鈕關(guān)閉')
 
 
if __name__ == '__main__':
    buttons()

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python與pycharm有何區(qū)別

    python與pycharm有何區(qū)別

    在本篇文章里小編給大家整理了關(guān)于pycharm與python的區(qū)別相關(guān)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2020-07-07
  • 使用Python刪除PDF中多余或空白頁(yè)面的實(shí)現(xiàn)步驟

    使用Python刪除PDF中多余或空白頁(yè)面的實(shí)現(xiàn)步驟

    在處理 PDF 文件時(shí),常常會(huì)遇到一些多余或空白的頁(yè)面,這些頁(yè)面不僅占據(jù)存儲(chǔ)空間,還會(huì)影響文檔的整潔性和可讀性,這篇文章將探討如何使用 Python刪除PDF中多余或空白的頁(yè)面,需要的朋友可以參考下
    2025-05-05
  • Python代碼實(shí)現(xiàn)復(fù)制PowerPoint幻燈片

    Python代碼實(shí)現(xiàn)復(fù)制PowerPoint幻燈片

    在處理演示文稿時(shí),復(fù)制幻燈片是一項(xiàng)非常實(shí)用的功能,本文將詳細(xì)介紹如何使用 Spire.Presentation for Python 庫(kù)復(fù)制 PowerPoint 幻燈片,,幫助你構(gòu)建完整的幻燈片管理解決方案
    2026-06-06
  • Python處理圖像并生成JSONL元數(shù)據(jù)文件

    Python處理圖像并生成JSONL元數(shù)據(jù)文件

    JSONL是一種輕量級(jí)的數(shù)據(jù)序列化格式,由一系列獨(dú)立的?JSON?對(duì)象組成,本文主要為大家介紹了Python如何處理圖像并生成JSONL元數(shù)據(jù)文件,感興趣的可以了解下
    2025-05-05
  • python批處理將圖片進(jìn)行放大實(shí)例代碼

    python批處理將圖片進(jìn)行放大實(shí)例代碼

    最近處理一些規(guī)格不一的照片,需要修改成指定尺寸便于打印,下面這篇文章主要給大家介紹了關(guān)于python批處理將圖片進(jìn)行放大的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-12-12
  • 探索Python?Slice函數(shù)靈活而強(qiáng)大的序列切片技術(shù)

    探索Python?Slice函數(shù)靈活而強(qiáng)大的序列切片技術(shù)

    Python中的Slice函數(shù)是一種強(qiáng)大且靈活的序列切片技術(shù),用于從字符串、列表、元組等序列類型中提取子集,本文將深入研究Slice函數(shù)的功能和用法,提供詳細(xì)的示例代碼和解釋,幫助讀者更全面地了解和應(yīng)用這一功能
    2024-01-01
  • 用Python遠(yuǎn)程登陸服務(wù)器的步驟

    用Python遠(yuǎn)程登陸服務(wù)器的步驟

    這篇文章主要介紹了用Python遠(yuǎn)程登陸服務(wù)器的步驟,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-04-04
  • python OpenCV 實(shí)現(xiàn)高斯濾波詳解

    python OpenCV 實(shí)現(xiàn)高斯濾波詳解

    這篇文章主要介紹了Python+OpenCV 實(shí)現(xiàn)高斯濾波的過(guò)程,關(guān)于高斯濾波的解釋,它是一種線性平滑濾波,適用于消除高斯噪聲,具體實(shí)現(xiàn)過(guò)程跟隨小編一起看看吧
    2021-10-10
  • tensorflow 初始化未初始化的變量實(shí)例

    tensorflow 初始化未初始化的變量實(shí)例

    今天小編就為大家分享一篇tensorflow 初始化未初始化的變量實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • pandas采樣的實(shí)現(xiàn)方法

    pandas采樣的實(shí)現(xiàn)方法

    pandas提供了多種方法進(jìn)行隨機(jī)采樣,包括指定數(shù)量、按比例、設(shè)置隨機(jī)種子、有無(wú)放回抽樣及按列和分層抽樣,下面就來(lái)介紹一下,感興趣的可以了解一下
    2024-12-12

最新評(píng)論

肃南| 成武县| 兴化市| 准格尔旗| 城固县| 林周县| 西峡县| 明溪县| 道孚县| 大足县| 依安县| 诸暨市| 南宁市| 探索| 台安县| 清流县| 即墨市| 安岳县| 安岳县| 通山县| 娱乐| 昆山市| 鹿泉市| 洛阳市| 托克逊县| 横峰县| 张家口市| 婺源县| 克东县| 彰武县| 益阳市| 武鸣县| 乐都县| 宜兴市| 阿图什市| 合川市| 平谷区| 宁国市| 长治县| 绥棱县| 梁平县|