亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python3使用tkinter實(shí)現(xiàn)ui界面簡單實(shí)例

 更新時(shí)間:2014年01月10日 10:33:04   作者:  
使用tkinter創(chuàng)建一個(gè)小窗口,布置2個(gè)按鈕,一個(gè)btn關(guān)閉窗口,另一個(gè)btn用于切換執(zhí)行傳入的2個(gè)函數(shù),簡單的小代碼,大家參考使用吧


復(fù)制代碼 代碼如下:

import time
import tkinter as tk

class Window:
    def __init__(self, title='nms', width=300, height=120, staFunc=bool, stoFunc=bool):
        self.w = width
        self.h = height
        self.stat = True
        self.staFunc = staFunc
        self.stoFunc = stoFunc
        self.staIco = None
        self.stoIco = None

        self.root = tk.Tk(className=title)

    def center(self):
        ws = self.root.winfo_screenwidth()
        hs = self.root.winfo_screenheight()
        x = int( (ws/2) - (self.w/2) )
        y = int( (hs/2) - (self.h/2) )
        self.root.geometry('{}x{}+{}+{}'.format(self.w, self.h, x, y))

    def packBtn(self):
        self.btnSer = tk.Button(self.root, command=self.event, width=15, height=3)
        self.btnSer.pack(padx=20, side='left')
        btnQuit = tk.Button(self.root, text='關(guān)閉窗口', command=self.root.quit, width=15, height=3)
        btnQuit.pack(padx=20, side='right')

    def event(self):
        self.btnSer['state'] = 'disabled'
        if self.stat:
            if self.stoFunc():
                self.btnSer['text'] = '啟動服務(wù)'
                self.stat = False
                self.root.iconbitmap(self.stoIco)
        else:
            if self.staFunc():
                self.btnSer['text'] = '停止服務(wù)'
                self.stat = True
                self.root.iconbitmap(self.staIco)
        self.btnSer['state'] = 'active'

    def loop(self):
        self.root.resizable(False, False)   #禁止修改窗口大小
        self.packBtn()
        self.center()                       #窗口居中
        self.event()
        self.root.mainloop()

########################################################################
def sta():
    print('start.')
    return True
def sto():
    print('stop.')
    return True

if __name__ == '__main__':
    import sys, os

    w = Window(staFunc=sta, stoFunc=sto)
    w.staIco = os.path.join(sys.exec_prefix, 'DLLs\pyc.ico')
    w.stoIco = os.path.join(sys.exec_prefix, 'DLLs\py.ico')
    w.loop()

相關(guān)文章

  • python基礎(chǔ)教程之自定義函數(shù)介紹

    python基礎(chǔ)教程之自定義函數(shù)介紹

    這篇文章主要介紹了python基礎(chǔ)教程之自定義函數(shù)介紹,本文講解了python中函數(shù)的定義方法、函數(shù)參數(shù)的定義方法,需要的朋友可以參考下
    2014-08-08
  • python中列表的常見操作梳理總結(jié)(二)

    python中列表的常見操作梳理總結(jié)(二)

    這篇文章主要介紹了python中列表的常見操作總結(jié),文章圍通過列表的索引與切片的相關(guān)資料展開全文詳細(xì)的內(nèi)容,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-07-07
  • 詳解Python的Django框架中的模版繼承

    詳解Python的Django框架中的模版繼承

    這篇文章主要介紹了詳解Python的Django框架中的模版繼承,就像Python中面對對象的方法繼承道理類似,需要的朋友可以參考下
    2015-07-07
  • python實(shí)現(xiàn)自動登錄

    python實(shí)現(xiàn)自動登錄

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)自動登錄,填充網(wǎng)頁表單,從而自動登錄WEB門戶,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • 解決win10 vscode 無法激活python 虛擬環(huán)境的問題

    解決win10 vscode 無法激活python 虛擬環(huán)境的問題

    這篇文章主要介紹了win10 vscode 無法激活python 虛擬環(huán)境的解決辦法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-10-10
  • 最新評論