pythongui实战案例(Python GUI编程完整示例)
类别:脚本大全 浏览量:1510
时间:2021-10-21 07:55:50 pythongui实战案例
Python GUI编程完整示例本文实例讲述了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 ( '获取目录内容中...' ) 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() |
效果如下:
希望本文所述对大家python程序设计有所帮助。
原文链接:https://www.cnblogs.com/wcwnina/p/8017834.html
您可能感兴趣
- python在txt指定行添加文本(Python修改文件往指定行插入内容的实例)
- python爬虫怎么爬取vip资源(Python网络爬虫之爬取微博热搜)
- python 多进程的启动和停止(Python3.5多进程原理与用法实例分析)
- python代码词频分析(python实现词法分析器)
- java怎么调用支付宝的扫码支付(python实现银联支付和支付宝支付接入)
- 用python简单实现登录功能(使用python的pexpect模块,实现远程免密登录的示例)
- centos8配置python开发环境(CentOS6.9 Python环境配置python2.7、pip、virtualenv)
- python try高级用法(python try 异常处理史上最全)
- python中的eval函数的用法(Python eval的常见错误封装及利用原理详解)
- python中list用法(Python数据类型之List列表实例详解)
- python自动计算机器人(python实现nao机器人手臂动作控制)
- python 文本分析 摘要(用Python逐行分析文件方法)
- pythonselenium自动选框(python selenium 弹出框处理的实现)
- python编写自动发送微信信息(python实现向微信用户发送每日一句 python实现微信聊天机器人)
- python与php(解决Python3 被PHP程序调用执行返回乱码的问题)
- python怎样读取mysql数据(使用Python将Mysql的查询数据导出到文件的方法)
- 这部动漫中的女孩子,可比101女孩更加励志(这部动漫中的女孩子)
- 《白狐的人生》热拍 贾征宇偶像包袱难自弃 图(白狐的人生热拍)
- 七夕取消了,牛郎织女没做核酸七夕已经取消(牛郎织女没做核酸七夕已经取消)
- 网友抵制 多地取消 夏日祭 为何惹众怒(网友抵制多地取消)
- 兄弟萌,今年的七夕又取消了 思考 思考(今年的七夕又取消了)
- 七夕取消是什么梗(七夕取消是什么梗)
热门推荐
- python图书管理系统(python面向对象法实现图书管理系统)
- php设计模式学习(PHP设计模式之PHP迭代器模式讲解)
- mysql 5.5.27 winx64安装配置方法图文教程(mysql 5.5.27 winx64安装配置方法图文教程)
- css垂直居中
- SQL Server 批量导入数据的方法
- css居中代码(CSS之居中布局的实现方法)
- js扫雷小游戏源代码(原生js实现简单贪吃蛇小游戏)
- 缓存系统机制(Smarty缓存机制实例详解三种缓存方式)
- mysql带log的版本(聊聊MYSQL中Redo Log是什么?)
- pyqt5怎么在pycharm中安装(pycharm+PyQt5+python最新开发环境配置踩坑)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9