主頁 > 知識庫 > python中Tkinter實現(xiàn)分頁標簽的示例代碼

python中Tkinter實現(xiàn)分頁標簽的示例代碼

熱門標簽:佛山通用400電話申請 打印谷歌地圖標注 看懂地圖標注方法 蘇州人工外呼系統(tǒng)軟件 電話機器人貸款詐騙 電話外呼系統(tǒng)招商代理 淮安呼叫中心外呼系統(tǒng)如何 廣東旅游地圖標注 京華圖書館地圖標注

Tkinter實現(xiàn)UI分頁標簽顯示:

Input頁,紅色部分為當前Frame的位置,下半部分為第一頁的子標簽;三頁標簽的顯示內(nèi)容各不相同。實現(xiàn)分頁顯示的核心組件為Radiobutton,Radiobutton只有一個選項能夠生效,使用參數(shù)indicatoron=0能夠?qū)adiobutton顯示為Button的形狀,通過選定的Radiobutton將原有的Frame forget掉,同時,將預(yù)定的Frame pack,實現(xiàn)分頁的效果。使用時要將更換的組件放入一個Frame中,定義一個函數(shù)進行選定Radiobutton的參數(shù)傳遞,實現(xiàn)切換。如果對Radiobutton使用bind的話,當前選定的Radiobutton只能在下次事件觸發(fā)時生效,始終慢著一拍,所以使用command選項賦值標簽切換函數(shù)。


第二頁Output


第三頁Ohter


第一頁的子標簽,分為三部分,每頁的內(nèi)容獨立



源碼如下:

import tkinter as tk

class TestBenchMaker:

    def __init__(self):
        self.TITLE = "Test"
        self.WIDTH = 500
        self.HEIGHT = 500
        self.parseDic = {}

    # Initial GUI
    def initialGUI(self):

        # Change tag
        def changeTag(tag):
            frame3.pack_forget()
            frame4.pack_forget()
            frame5.pack_forget()
            if tag == 0:
                frame3.pack(fill=tk.X)
            elif tag == 1:
                frame4.pack(fill=tk.X)
            elif tag == 2:
                frame5.pack(fill=tk.X)

        # Change type
        def changeType(tag):
            clockSet.pack_forget()
            resetSet.pack_forget()
            customSet.pack_forget()
            if tag == 0:
                clockSet.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES, pady=5, padx=10)
            elif tag == 1:
                resetSet.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES, pady=5, padx=10)
            elif tag == 2:
                customSet.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES, pady=5, padx=10)


        window = tk.Tk()
        window.title(self.TITLE)

        # Place GUI on the center of screen
        self.ws = window.winfo_screenwidth()
        self.hs = window.winfo_screenheight()
        x = (self.ws / 2) - (self.WIDTH / 2)
        y = (self.hs / 2) - (self.HEIGHT / 2)
        window.geometry('%dx%d+%d+%d' % (self.WIDTH, self.HEIGHT, x, y))



        # Tag: 0 --> input; 1 --> output; 2 --> other
        frame2 = tk.Frame(window)
        frame2.pack(fill=tk.Y, pady=10)
        tag = tk.IntVar()
        tagWidth = 23
        tk.Radiobutton(frame2, text="Input", command=lambda: changeTag(0), width=tagWidth, variable=tag, value=0, bd=1, indicatoron=0).grid(column=0, row=1)
        tk.Radiobutton(frame2, text="Output", command=lambda: changeTag(1), variable=tag, width=tagWidth, value=1, bd=1, indicatoron=0).grid(column=1, row=1)
        tk.Radiobutton(frame2, text="Other", command=lambda: changeTag(2), variable=tag, width=tagWidth, value=2, bd=1, indicatoron=0).grid(column=2, row=1)

        # frame3 --> Input
        # Signal info
        frame3 = tk.Frame(window, height=300, bg="red")
        frame3.pack(side=tk.TOP, fill=tk.X)
        tk.Label(frame3, text=" Bit         Input").pack(side=tk.TOP, anchor=tk.W)
        scroll = tk.Scrollbar(frame3)
        scroll.pack(side=tk.RIGHT, fill=tk.Y)
        self.inputBox = tk.Listbox(frame3, bd=1, selectmode=tk.SINGLE, yscrollcommand=scroll.set, height=8)
        self.inputBox.pack(side=tk.TOP, anchor=tk.NW, fill=tk.X, expand=tk.YES)
        scroll.config(command=self.inputBox.yview)

        # Input setting
        width = 10
        frameInputSet = tk.Frame(frame3, bg="white")
        frameInputSet.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES)
        tk.Label(frameInputSet, text="  Input Setting").grid(row=0, column=0, pady=5)
        tk.Label(frameInputSet, text="  Signal Type", width=width).grid(row=1, column=0)
        # Tpye: 0 --> clock; 1 --> reset; 2 --> custom
        type = tk.IntVar()
        tk.Radiobutton(frameInputSet, text="Clock", variable=type, value=0, command=lambda:changeType(0), bd=1, indicatoron=0, width=width).grid(row=1, column=1, padx=10)
        tk.Radiobutton(frameInputSet, text="Reset", variable=type, value=1, command=lambda:changeType(1), bd=1, indicatoron=0, width=width).grid(row=1, column=2, padx=10)
        tk.Radiobutton(frameInputSet, text="Custom", variable=type, value=2, command=lambda:changeType(2), bd=1, indicatoron=0, width=width).grid(row=1, column=3, padx=10)
        # Clock setting
        initalValue = tk.StringVar()
        initalValue.set("1'b0")
        cycle = tk.StringVar()
        converse = tk.StringVar()
        clockSet = tk.Frame(frame3, bg="white")
        #clockSet.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES, pady=5, padx=10)
        tk.Label(clockSet, text="Initial Value").grid(row=0, column=0, pady=5)
        tk.Radiobutton(clockSet, text="1'b0", variable=initalValue, value="1'b0").grid(row=0, column=1, padx=5)
        tk.Radiobutton(clockSet, text="1'b1", variable=initalValue, value="1'b1").grid(row=0, column=2, padx=5)
        tk.Label(clockSet, text="", width=10).grid(row=0, column=3)
        tk.Label(clockSet, text="Cycle").grid(row=0, column=4, pady=5, padx=10)
        tk.Entry(clockSet, textvariable=cycle, width=10, bd=2, bg="white").grid(row=0, column=5)
        # Reset setting
        resetSet = tk.Frame(frame3, bg="white")
        tk.Label(resetSet, text="Initial Value").grid(row=0, column=0, pady=5)
        tk.Radiobutton(resetSet, text="1'b0", variable=initalValue, value="1'b0").grid(row=0, column=1, padx=5)
        tk.Radiobutton(resetSet, text="1'b1", variable=initalValue, value="1'b1").grid(row=0, column=2, padx=5)
        tk.Label(resetSet, text="", width=10).grid(row=0, column=3)
        tk.Label(resetSet, text="Converse").grid(row=0, column=4, pady=5, padx=10)
        tk.Entry(resetSet, textvariable=converse, width=10, bd=2, bg="white").grid(row=0, column=5)
        # Custom setting
        defaultValue = tk.IntVar()
        radixValue = tk.IntVar()
        radixValue.set(0)
        customSet = tk.Frame(frame3, bg="white")
        customSet.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES, pady=5, padx=10)
        # Radix 0 --> b, 1 --> o, 2 --> d, 3 --> h
        tk.Label(customSet, text="Radix").grid(row=0, column=0, pady=5, padx=1)
        tk.Radiobutton(customSet, text="Binary", variable=radixValue, value=0).grid(row=0, column=1)
        tk.Radiobutton(customSet, text="Octal", variable=radixValue, value=1).grid(row=0, column=2)
        tk.Radiobutton(customSet, text="Decimal", variable=radixValue, value=2).grid(row=0, column=3)
        tk.Radiobutton(customSet, text="Hexadecimal", variable=radixValue, value=3).grid(row=0, column=4)
        # Initial value
        tk.Label(customSet, text="Default Value").grid(row=1, column=0, pady=5, padx=10)
        tk.Radiobutton(customSet, text="default 0", variable=defaultValue, value=0).grid(row=1, column=1, padx=5)
        tk.Radiobutton(customSet, text="default 1", variable=defaultValue, value=1).grid(row=1, column=2, padx=5)
        tk.Label(customSet, text="Initial Value").grid(row=1, column=3, pady=5, padx=5)
        tk.Entry(customSet, textvariable=initalValue, width=12, bd=2, bg="white", justify=tk.RIGHT).grid(row=1, column=4)
        tk.Button(customSet, text="test", command=lambda :print(initalValue.get())).grid()

        # frame4 --> Output
        frame4 = tk.Frame(window, height=350, bg="blue")
        tk.Label(frame4, text=" Bit         Output").pack(anchor=tk.NW)
        scroll2 = tk.Scrollbar(frame4)
        scroll2.pack(side=tk.RIGHT, fill=tk.Y)

        self.outputBox = tk.Listbox(frame4, bd=1, selectmode=tk.SINGLE, yscrollcommand=scroll2.set, height=8, width=65)
        self.outputBox.pack(side=tk.LEFT)
        scroll2.config(command=self.outputBox.yview)

        # frame5 --> Other
        frame5 = tk.Frame(window, height=350, bg="yellow")

        window.mainloop()

if __name__ == "__main__":
    tbm = TestBenchMaker()
    tbm.initialGUI()

到此這篇關(guān)于python中Tkinter實現(xiàn)分頁標簽的示例代碼的文章就介紹到這了,更多相關(guān)python Tkinter分頁標簽內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • python爬蟲之異常捕獲及標簽過濾詳解
  • python 如何獲取頁面所有a標簽下href的值
  • Python深度學(xué)習之圖像標簽標注軟件labelme詳解
  • Python 實現(xiàn)自動完成A4標簽排版打印功能
  • Python氣泡提示與標簽的實現(xiàn)
  • Python 生成VOC格式的標簽實例
  • 基于python3生成標簽云代碼解析
  • python 實現(xiàn)添加標簽&打標簽的操作

標簽:中山 畢節(jié) 江蘇 衡水 呼和浩特 股票 湖州 駐馬店

巨人網(wǎng)絡(luò)通訊聲明:本文標題《python中Tkinter實現(xiàn)分頁標簽的示例代碼》,本文關(guān)鍵詞  python,中,Tkinter,實現(xiàn),分頁,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《python中Tkinter實現(xiàn)分頁標簽的示例代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于python中Tkinter實現(xiàn)分頁標簽的示例代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章