技术标签: 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('', 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('', 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编程之gui程序实现简单文件浏览器代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:
Python中pygal绘制雷达图代码分享
pip和pygal的安装实例教程
Python编程实现使用线性回归预测数据
如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
文章浏览阅读395次。17 有两个整型变量dog和cat,若要从磁盘文件把数据读到其中,正确的形式是( ). BA、fscanf(dog ,2,1,fp);B、fscanf(fp,"%d%d",&dog ,&cat);C、fscanf(dog ,cat,2,1,fp);D、fscanf(fp,"%d",&dog ,&cat);二、程序设计:/*----------------------..._有两个整型变量dog和cat,若要从磁盘文件把数据读到其中,正确的形式是
文章浏览阅读339次。在编写该exe文件的时候,首先需要知道需要那些工具以及思路和需求,这样才能更好的解决整体设计以及调整方案。_python excel整行标记
文章浏览阅读4.2k次,点赞25次,收藏15次。本书为IT服务交付团队及其领导者撰写,从精益思想和精益管理的视角,深入探讨了DevOps方法的核心要素(如任务式指挥、摩擦、风险、态势感知等),并结合实际案例,阐述了如何通过DevOps方法解决IT服务交付中的各种问题,如何在整个组织内改善信息流,从而向客户的目标成果迈进。此外,本书还提供了许多实用的工具和技巧,包括OODA循环、Cynefin框架、服务交付的成熟度模型和服务工程负责人等,以帮助读者更好地应用DevOps方法。_devops平台提升效率
文章浏览阅读4.2k次。在对应的less文件下,设置样式:global .CodeMirror { /* Set height, width, borders, and global font properties here */ font-family: monospace; height: auto; color: black; direction: ltr;}..._react codemirror 自适应高度
文章浏览阅读1.5k次。百问网STM32157适配正点原子7寸电容屏(1024X600)文章目录1.修改设备树文件2.修改edt-ft5x06.c(触摸驱动)3.修改QT环境变量(重要,踩坑)1.修改设备树文件由于百问网STM32MP157的触摸IC与HDMI驱动IC复用,因此需要完成以下几个步骤(1)在stm32mp157c-100ask-512d-lcd-v1.dts文件中对i2c4节点增加ft5x06触摸的描述信息,具体参考正点原子STM32MP157开发板的配套源码,如下在正点原子出厂linux源码中找到stm3_touchscreen-size-x
文章浏览阅读901次。clcclearall%一、初始化部分%1.1预处理样本数据%选取训练样本(x,y)fori=1:126x=0+0.0251*(i-1);y(i)=(sin(x)+(x.^2/9+x/3)*exp((-0.5)*(x.^2)))/2;%待逼近函数endAllSamIn=0:0.0251:pi;%训练样本输入AllSamOut=y;%训练样本输出%选取测试样本fori=1:125x=0.0125+..._pid神经网络优化 python
文章浏览阅读1.6k次,点赞2次,收藏6次。// 获得总记录数(行数) int lastRowNum = sheet.getLastRowNum(); int rowNum=sheet.getPhysicalNumberOfRows();同样的都是获取Excel工作sheet行数的两个方法getLastRowNum()getPhysicalNumberOfRows()他们的主..._sheet.getphysicalnumberofrows
文章浏览阅读1k次,点赞12次,收藏21次。本文主要记录一些在工作中经常能用到的excel技巧,能够帮助我们提高工作效率。在文章的最后还会通过几个实战例子来加深大家的理解。建议把本文作为备查文,不需要在阅读本文的当下就将这些技巧掌握,只需了解,哪些东西通过excel是能够做到的,再实际工作中遇到问题的时候再来查阅。【不要被vba吓到,配合chatgpt,每一个没有学过代码的人都能够搞定80%的vba编写宏的需求!】_excel 价格处理技巧
文章浏览阅读5.5k次,点赞41次,收藏106次。AlexNet(ImageNet Classification with Deep Convolutional Neural Networks)论文超详细解读。翻译+总结_alexnet论文
文章浏览阅读1.1w次,点赞12次,收藏36次。Motivation两周前实验室要求我配置一个叫Speedy.js的编译器,配置这个编译器需要先配置好LLVM。根据这个编译器作者的教程,乱七八糟配置了一通,踩过一些坑,碰过一些雷,浪费了很多时间。花了两周时间,终于全套配置完成,因此想写个教程,留点知识给以后的自己和需要的各位。Speedy.js不好说,但是LLVM这东西以后有大概率会用的上。环境这是我这次配置LLVM过程中最大的_ubuntu hexagon llvm 8.5.09
文章浏览阅读1.9k次,点赞7次,收藏15次。2022年6月13日-记录Anaconda+tensorflow_gpu-2.9.0+spyder5.3.1+py3.9安装过程,回忆一下踩过的坑_anaconda navigator安装spyderd慢
文章浏览阅读2.6k次。_数据预处理流程图