Python编程之gui程序实现简单文件浏览器代码
作者:过去不再从来 发布时间:2021-08-20 11:09:36
标签:python,gui编程
本文主要分享了关于在python中实现一个简单的文件浏览器的代码示例,代码及展示如下。
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
from time import sleep
from Tkinter import *
class DirList(object):
def __init__(self, initdir=None):
'''构造函数,说明版本信息'''
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()
结果:
代码实现功能较简单,感兴趣的朋友参考下吧!
Python中pygal绘制雷达图代码分享
pip和pygal的安装实例教程
Python编程实现使用线性回归预测数据
如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
来源:http://blog.csdn.net/youhaibo1990/article/details/50574425
![](https://www.aspxhome.com/images/zang.png)
![](https://www.aspxhome.com/images/jiucuo.png)
猜你喜欢
- 原文作者:青女 附注及色样添加:Quester西式的色名及色样表,可以参见以下链接 (Java 类色彩兼容):http
- 项目场景:在使用selenium模块进行数据爬取时,通常会遇到爬取iframe中的内容。会因为定位的作用域问题爬取不到数据。问题描述:我们以
- Oracle的Nvl函数nvl( ) 函数从两个表达式返回一个非null 值。语法NVL(eExpression1, eExpression
- 数据可视化是任何探索性数据分析或报告的关键步骤,它可以让我们一眼就能洞察数据集。目前有许多非常好的商业智能工具,比如Tableau、goog
- 重置oracle序列从指定数字开始 代码如下:declare n number(10); v_startnum number(10):=1
- 本博文源于绘图基础,主要讲解如何用python的plot绘制气温的折线图。先讲解plot参数如何使用后给出一个气温折线图样例绘制使用plot
- 兼容当前HTML/XHTML文档是否有DTD声明:以下为程序代码:var xtop = document.documentElement.s
- 程序说明:本程序实现将开发程序服务器中的打包文件通过该脚本上传到正式生产环境(注:生产环境和开发环境不互通)程序基本思路:将开发环境中的程序
- 这篇文章主要介绍了python3.8 微信发送服务器监控报警消息代码实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考
- python简单实现最大似然估计1、scipy库的安装wim+R输入cmd,然后cd到python的pip路径,即安装:pip instal
- test.asp 测试演示文件clsrsa.asp 实现rsa加密与解密的vbs类文件下面是代码:1. test.asp<%rem 文
- 认识pip众所周知,pip可以对python的第三方库进行安装、更新、卸载等操作,十分方便。pip的全称:package installer
- 下面的代码是从kesion系统扒下的,确实不错,支持utf8格式。代码如下:'===========================
- Go语言集成开发环境之VS Code安装使用VS Code是微软开源的一款编辑器,插件系统十分的丰富。下面介绍如何用VS Code搭建go语
- 本文是小编日常收集整理些js经典实例,特此分享供大家参考!跨浏览器添加事件//跨浏览器添加事件function addEvent(obj,t
- using System; using System.Collections; using System.Configuration; us
- 1. 为什么需要Simhash?传统相似度算法:文本相似度的计算,一般使用向量空间模型(VSM),先对文本分词,提取特征,根据特征建立文本向
- 大家好,我是安果!目前公司使用 Jira 作为项目管理工具,在每一次迭代完成后的复盘会上,我们都需要针对本次迭代的&nb
- Python作为一种功能强大的编程语言,因其简单易学而受到很多开发者的青睐。那么,Python 的应用领域有哪些呢?概括起来,Python的
- 如何正确理解MIME类型?mime联系介绍。序号内容类型文件扩展名描述1application/msworddocMicrosoft Wor