Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1753423
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: Python/Ruby

2013-04-18 22:32:14

        在昨天的基础上进行了一些改建(在我看来),如整体的布局:
增加了右边的滚动条,文本区域的滚动条没有生效(具体的原因还在调试中)
涉及的知识点:
事件绑定  bind  ,通过使用回车,可以自动的刷新文本区域内容
scrollbar 与TEXT的联合使用方法

点击(此处)折叠或打开

  1. # -*- coding: cp936 -*-
  2. __author__ = 'kinfinger'
  3. import os
  4. import time
  5. import tkFileDialog
  6. import tkMessageBox
  7. from Tkinter import *


  8. class FileGuiChose(object):
  9.     def __init__(self,initdir=None,frame=None,showframe=None,bottomFrame=None):
  10.         self.entryvar =StringVar()
  11.         self.showframe=showframe
  12.         # top area
  13.         self.glabel=Label(frame,text=u'你选择的目录为:')
  14.         self.gentry=Entry(frame,textvariable=self.entryvar)
  15.         self.gbutton=Button(frame,command=self.opendir,text=u'选取目录')
  16.         self.gentry.bind('',func=self.refresh)
  17.         self.glabel.grid(row=0,column=0)
  18.         self.gentry.grid(row=0,column=1)
  19.         self.gbutton.grid(row =0,column=2)
  20.         # content area
  21.         self.textbar=Scrollbar(self.showframe,orient=VERTICAL)
  22.         self.textbar.pack(side=RIGHT,fill=Y)
  23.         # bottome area
  24.         self.bottomBar = Scrollbar(showframe,orient = HORIZONTAL,bg='black')
  25.         self.bottomBar.pack(side=BOTTOM,fill=X)
  26.         self.textbox=Text(self.showframe,yscrollcommand=self.textbar.set,xscrollcommand=self.bottomBar.set)
  27.         self.textbox.pack(side=LEFT,fill=BOTH)
  28.         self.textbar.config(command=self.textbox.yview) # yview
  29.         self.bottomBar.config(command=self.textbox.xview) # xview
  30.     def opendir(self):
  31.         self.dirname=tkFileDialog.askdirectory()
  32.         self.entryvar.set(self.dirname) # related to entry just for show
  33.         showmessage='just for tip!'
  34.         if not self.dirname:
  35.             self.messageBox=tkMessageBox.showinfo(self.showframe,message=showmessage)
  36.         self.dirlist=os.listdir(self.entryvar.get())
  37.         for eachdir in self.dirlist:
  38.             self.textbox.insert(END,eachdir+'\r\n')
  39.         self.textbox.update()
  40.     def refresh(self,event=None):
  41.         self.textbox.delete('1.0','9999.0')
  42.         self.dirlist=os.listdir(self.entryvar.get())
  43.         for eachdir in self.dirlist:
  44.             self.textbox.insert(END,unicode(eachdir,'cp936')+'\r\n')
  45.         self.textbox.update()
  46. class GuiMenu():
  47.     def hello(self):
  48.         pass
  49.     def File(self):
  50.         pass
  51.     def Edit(self):
  52.         pass
  53.     def View(self):
  54.         pass
  55.     def Help(self):
  56.         tkMessageBox.showinfo(self.root,u'作者 kinfinger \n verion 1.0 \n Thank you ')
  57.     def __init__(self,rootmenu):
  58.         self.root=rootmenu
  59.         self.menubar=Menu(rootmenu)
  60.         rootmenu['menu']=self.menubar
  61.         self.menubar.add_command(label = 'File',command =self.File )
  62.         self.menubar.add_command(label = 'Edit',command =self.Edit )
  63.         self.menubar.add_command(label = 'View',command =self.View )
  64.         self.menubar.add_command(label = 'Help',command =self.Help)
  65. def main():
  66.     root = Tk()
  67.     topFrame=Frame(root,bg='red')
  68.     contentFrame=Frame(root,bg='white')
  69.     bottomFrame=Frame(root,bg='green')
  70.     topFrame.pack(side=TOP)
  71.     contentFrame.pack(side=TOP)
  72.     bottomFrame.pack(side=TOP)
  73.     GuiMenu(root)
  74.     fguiChose=FileGuiChose(os.curdir,topFrame,contentFrame,bottomFrame)
  75.     mainloop()
  76. if __name__ == '__main__':
  77.     main()


ref:
阅读(1733) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~