欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python編程之gui程序?qū)崿F(xiàn)簡單文件瀏覽器代碼

 更新時間:2017年12月08日 09:23:25   作者:過去不再從來  
這篇文章主要介紹了Python編程之gui程序?qū)崿F(xiàn)簡單文件瀏覽器代碼,具有一定借鑒價值,需要的朋友可以了解下。

本文主要分享了關(guān)于在python中實現(xiàn)一個簡單的文件瀏覽器的代碼示例,代碼及展示如下。

#!/usr/bin/env python
# -*- coding: UTF-8 -*- 
import os
from time import sleep
from Tkinter import * 

class DirList(object):
  def __init__(self, initdir=None):
    '''構(gòu)造函數(shù),說明版本信息'''
    self.top = Tk()
    self.label = Label(self.top, 
      text = 'My directory Lister v1.1')
    self.label.pack()
    self.cwd = StringVar(self.top)
    self.dir1 = Label(self.top, 
      fg='blue', font=('Helvetica', 22, 'bold'))
    self.dir1.pack()
    self.dirfm = Frame(self.top)
    self.dirsb = Scrollbar(self.dirfm)
    self.dirsb.pack(side=RIGHT, fill=Y)
    self.dirs = Listbox(self.dirfm, height=15,
      width=50, yscrollcommand=self.dirsb.set)
    self.dirs.bind('<Double-1>', self.setDirAndGo)
    self.dirsb.config(command=self.dirs.yview)
    self.dirs.pack(side=LEFT, fill=BOTH)
    self.dirfm.pack()
    self.dirn = Entry(self.top, width=50,
      textvariable=self.cwd)
    self.dirn.bind('<Return>', self.doLS)
    self.dirn.pack()
    self.bfm = Frame(self.top)
    self.clr = Button(self.bfm, text='Clear',
      command = self.clrDir,
      activeforeground = 'white',
      activebackground = 'blue')
    self.ls = Button(self.bfm, 
      text = 'List Directory',
      command = self.doLS,
      activeforeground = 'white',
      activebackground = 'green')
    self.quit = Button(self.bfm, text='Quit',
      command=self.top.quit,
      activeforeground='white',
      activebackground='red')
    self.clr.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 clrDir(self, ev=None):
    self.cwd.set('')
  def setDirAndGo(self, ev=None):
    self.last = self.cwd.get()
    self.dirs.config(selectbackground='red')
    check = self.dirs.get(self.dirs.curselection())
    if not check:
      check = os.curdir
    self.cwd.set(check)
    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 + ': no such file'
    elif not os.path.isdir(tdir):
      error = tdir + ': not a directory'
    if error:
      self.cwd.set(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
    self.cwd.set(\
      'FETCHING DIRECTORY CONTENTS...')
    self.top.update()
    dirlist = os.listdir(tdir)
    dirlist.sort()
    os.chdir(tdir)
    self.dir1.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 main():
  d = DirList(os.curdir)
  mainloop()
if __name__ == '__main__':
  main()

結(jié)果:

代碼實現(xiàn)功能較簡單,感興趣的朋友參考下吧!

以上就是本文關(guān)于Python編程之gui程序?qū)崿F(xiàn)簡單文件瀏覽器代碼的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:

Python中pygal繪制雷達圖代碼分享

pip和pygal的安裝實例教程

Python編程實現(xiàn)使用線性回歸預(yù)測數(shù)據(jù)

如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

相關(guān)文章

  • django如何通過類視圖使用裝飾器

    django如何通過類視圖使用裝飾器

    這篇文章主要介紹了django如何設(shè)計裝飾器過濾黑名單,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-07-07
  • Python按指定列的空值刪除行的操作代碼

    Python按指定列的空值刪除行的操作代碼

    這篇文章主要介紹了Python按指定列的空值刪除行的操作代碼,本文通過實例代碼給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧
    2024-01-01
  • 簡單了解python代碼優(yōu)化小技巧

    簡單了解python代碼優(yōu)化小技巧

    這篇文章主要介紹了簡單了解python代碼優(yōu)化小技巧,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值
    2019-07-07
  • python計算機視覺opencv卡號識別示例詳解

    python計算機視覺opencv卡號識別示例詳解

    這篇文章主要為大家介紹了python計算機視覺opencv卡號識別的實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下 希望能夠有所幫助,祝大家多多進步
    2021-11-11
  • python socket 聊天室實例代碼詳解

    python socket 聊天室實例代碼詳解

    在本篇文章里小編給大家整理了關(guān)于python socket 聊天室的相關(guān)知識點,需要的朋友們參考下。
    2019-11-11
  • 詳解Python中映射類型的內(nèi)建函數(shù)和工廠函數(shù)

    詳解Python中映射類型的內(nèi)建函數(shù)和工廠函數(shù)

    這篇文章主要介紹了詳解Python中映射類型的內(nèi)建函數(shù)和工廠函數(shù),目前Python的內(nèi)建映射類型只有字典一種,需要的朋友可以參考下
    2015-08-08
  • Selenium啟動Chrome時配置選項詳解

    Selenium啟動Chrome時配置選項詳解

    這篇文章主要介紹了Selenium啟動Chrome時配置選項詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • pytorch 模型的train模式與eval模式實例

    pytorch 模型的train模式與eval模式實例

    今天小編就為大家分享一篇pytorch 模型的train模式與eval模式實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • python簡單實現(xiàn)獲取當(dāng)前時間

    python簡單實現(xiàn)獲取當(dāng)前時間

    最近項目中經(jīng)常需要python去取當(dāng)前的時間,雖然不是很難,但是老是忘記,用一次丟一次,為了能夠更好的記住,我今天特意寫下python 當(dāng)前時間這篇文章,如果你覺的對你有用的話,可以收藏下。
    2016-08-08
  • Keras: model實現(xiàn)固定部分layer,訓(xùn)練部分layer操作

    Keras: model實現(xiàn)固定部分layer,訓(xùn)練部分layer操作

    這篇文章主要介紹了Keras: model實現(xiàn)固定部分layer,訓(xùn)練部分layer操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06

最新評論