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

Python GUI編程完整示例

 更新時間:2019年04月04日 10:42:20   作者:薔薇Nina  
這篇文章主要介紹了Python GUI編程,結(jié)合完整示例形式分析了Python基于tkinter模塊的GUI圖形界面編程相關(guān)實現(xiàn)技巧,需要的朋友可以參考下

本文實例講述了Python GUI編程。分享給大家供大家參考,具體如下:

import os
from time import sleep
from tkinter import *
from tkinter.messagebox import showinfo
class DirList(object):
  def __init__(self, initdir=None):
    self.top = Tk()
    self.label = Label(master=self.top, text='Directory Lister V1.0')
    self.label.pack()
    self.cwd = StringVar(master=self.top)
    self.dirl = Label(self.top, fg='blue', font=('Helvetica', 14, 'bold'))
    self.dirl.pack()
    self.dirfm = Frame(master=self.top)
    self.dirsb = Scrollbar(master=self.dirfm)
    self.dirsb.pack(side=RIGHT,fill=Y)    # fill=Y,垂直填充空間排列
    self.dirs = Listbox(master=self.dirfm, height=15, width=50, yscrollcommand=self.dirsb.set)
    self.dirs.bind('<Double-1>', func=self.setDirAndGo)    # <Double-1>,雙擊顯示路徑列表
    self.dirsb.config(command=self.dirs.yview)
    self.dirs.pack(side=LEFT, fill=BOTH)
    self.dirfm.pack()
    self.dirn = Entry(master=self.top, width=50, textvariable=self.cwd)
    self.dirn.bind('<Return>', func=self.doLS)
    self.dirn.pack()
    self.bfm = Frame(master=self.top)
    self.cleer = Button(master=self.bfm, text='清除', command=self.clrDir, activeforeground='white',
             activebackground='blue')
    self.ls = Button(master=self.bfm, text='顯示列表', command=self.doLS, activeforeground='white',
             activebackground='green')
    self.quit = Button(master=self.bfm, text='退出', command=self.top.quit, activeforeground='white',
              activebackground='red')
    self.cleer.pack(side=LEFT)
    self.ls.pack(side=LEFT)
    self.quit.pack(side=LEFT)
    self.bfm.pack()
    if initdir:
      self.cwd.set(os.curdir)
      self.doLS()
  def setDirAndGo(self, ev=None):
    self.last = self.cwd.get()
    self.dirs.config(selectbackground='red')
    chek = self.dirs.get(self.dirs.curselection())
    if not chek:
      chek = os.curdir
    self.cwd.set(chek)
    self.doLS()
  def doLS(self, ev=None):
    error = ''
    tdir = self.cwd.get()
    if not tdir:
      tdir = os.curdir
    if not os.path.exists(tdir):
      error = tdir + ':未找到文件,請檢查路徑!'
    elif not os.path.isdir(tdir):
      error = tdir + ':不是一個路徑!'
    if error:
      # self.cwd.set(error)
      showinfo(title='提示',message=error)
      self.top.update()
      # sleep(2)
      if not (hasattr(self, 'last') and self.last):
        self.last = os.curdir
        self.cwd.set(self.last)
        self.dirs.config(selectbackground='LightSkyBlue')
        self.top.update()
        return
    if not os.path.isdir(tdir):
      self.cwd.set('')
    else:
      self.cwd.set('獲取目錄內(nèi)容中...')
    self.top.update()
    dirlist = os.listdir(tdir)
    dirlist.sort()
    os.chdir(tdir)
    self.dirl.config(text=os.getcwd())
    self.dirs.delete(0, END)
    self.dirs.insert(END, os.curdir)
    self.dirs.insert(END, os.pardir)
    for eachfile in dirlist:
      self.dirs.insert(END, eachfile)
    self.cwd.set(os.curdir)
    self.dirs.config(selectbackground='LightSkyBlue')
  def clrDir(self, ev=None):
    self.cwd.set('')
if __name__ == '__main__':
  dir = DirList(os.curdir)
  mainloop()

效果如下:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設(shè)計有所幫助。

相關(guān)文章

  • Python 找出英文單詞列表(list)中最長單詞鏈

    Python 找出英文單詞列表(list)中最長單詞鏈

    這篇文章主要介紹了Python 找出英文單詞列表(list)中最長單詞鏈,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Python 調(diào)用DLL操作抄表機

    Python 調(diào)用DLL操作抄表機

    Python 調(diào)用DLL的實用代碼。
    2009-01-01
  • Python發(fā)送郵件測試報告操作實例詳解

    Python發(fā)送郵件測試報告操作實例詳解

    這篇文章主要介紹了Python發(fā)送郵件測試報告操作,結(jié)合實例形式較為詳細的分析了Python郵件發(fā)送相關(guān)模塊使用及操作注意事項,需要的朋友可以參考下
    2018-12-12
  • python生成器generator用法實例分析

    python生成器generator用法實例分析

    這篇文章主要介紹了python生成器generator用法,實例分析了python生成器的相關(guān)使用技巧,需要的朋友可以參考下
    2015-06-06
  • python必備庫Matplotlib畫圖神器

    python必備庫Matplotlib畫圖神器

    這篇文章主要介紹了python必備庫Matplotlib畫圖神器,Matplotlib 是 Python 中最受歡迎的數(shù)據(jù)可視化軟件包之一,支持跨平臺運行,它是 Python 常用的 2D 繪圖庫,同時它也提供了一部分 3D 繪圖接口,更多詳細內(nèi)容,需要的小伙伴可以參考一下下面文章具體內(nèi)容
    2022-03-03
  • pytorch基礎(chǔ)之損失函數(shù)與反向傳播詳解

    pytorch基礎(chǔ)之損失函數(shù)與反向傳播詳解

    損失函數(shù)(Loss?Function)用于衡量神經(jīng)網(wǎng)絡(luò)輸出與目標值之間的誤差,指導(dǎo)網(wǎng)絡(luò)通過反向傳播優(yōu)化參數(shù),常見的損失函數(shù)包括均方誤差和交叉熵誤差,在訓(xùn)練過程中,通過不斷最小化損失函數(shù)值來調(diào)整網(wǎng)絡(luò)權(quán)重,以期達到輸出接近目標值的效果
    2024-09-09
  • 在雙python下設(shè)置python3為默認的方法

    在雙python下設(shè)置python3為默認的方法

    這篇文章主要介紹了如何在雙python下設(shè)置python3為默認,本文通過一個例子分步驟給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-10-10
  • python繪制ROC曲線的示例代碼

    python繪制ROC曲線的示例代碼

    本文主要介紹了python繪制ROC曲線的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • Python實現(xiàn)的字典值比較功能示例

    Python實現(xiàn)的字典值比較功能示例

    這篇文章主要介紹了Python實現(xiàn)的字典值比較功能,可實現(xiàn)針對字典格式數(shù)據(jù)的判斷、比較功能,涉及Python字典格式數(shù)據(jù)的遍歷、判斷等相關(guān)操作技巧,需要的朋友可以參考下
    2018-01-01
  • 使用Python實現(xiàn)畫一個中國地圖

    使用Python實現(xiàn)畫一個中國地圖

    今天小編就為大家分享一篇使用Python實現(xiàn)畫一個中國地圖,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11

最新評論

镇赉县| 叶城县| 安宁市| 成安县| 新津县| 易门县| 华宁县| 济宁市| 大港区| 衡南县| 南召县| 固镇县| 满洲里市| 华容县| 林周县| 宁明县| 什邡市| 蒙阴县| 安陆市| 泸定县| 东明县| 双江| 修文县| 三门县| 横山县| 上杭县| 咸丰县| 中阳县| 武穴市| 澜沧| 广南县| 桦南县| 上杭县| 昌平区| 天等县| 西青区| 福鼎市| 贵港市| 文山县| 陵水| 宜宾县|