在昨天的基础上进行了一些改建(在我看来),如整体的布局:
增加了右边的滚动条,文本区域的滚动条没有生效(具体的原因还在调试中)
涉及的知识点:
事件绑定 bind ,通过使用回车,可以自动的刷新文本区域内容
scrollbar 与TEXT的联合使用方法
-
# -*- coding: cp936 -*-
-
__author__ = 'kinfinger'
-
import os
-
import time
-
import tkFileDialog
-
import tkMessageBox
-
from Tkinter import *
-
-
-
class FileGuiChose(object):
-
def __init__(self,initdir=None,frame=None,showframe=None,bottomFrame=None):
-
self.entryvar =StringVar()
-
self.showframe=showframe
-
# top area
-
self.glabel=Label(frame,text=u'你选择的目录为:')
-
self.gentry=Entry(frame,textvariable=self.entryvar)
-
self.gbutton=Button(frame,command=self.opendir,text=u'选取目录')
-
self.gentry.bind('',func=self.refresh)
-
self.glabel.grid(row=0,column=0)
-
self.gentry.grid(row=0,column=1)
-
self.gbutton.grid(row =0,column=2)
-
# content area
-
self.textbar=Scrollbar(self.showframe,orient=VERTICAL)
-
self.textbar.pack(side=RIGHT,fill=Y)
-
# bottome area
-
self.bottomBar = Scrollbar(showframe,orient = HORIZONTAL,bg='black')
-
self.bottomBar.pack(side=BOTTOM,fill=X)
-
self.textbox=Text(self.showframe,yscrollcommand=self.textbar.set,xscrollcommand=self.bottomBar.set)
-
self.textbox.pack(side=LEFT,fill=BOTH)
-
self.textbar.config(command=self.textbox.yview) # yview
-
self.bottomBar.config(command=self.textbox.xview) # xview
-
def opendir(self):
-
self.dirname=tkFileDialog.askdirectory()
-
self.entryvar.set(self.dirname) # related to entry just for show
-
showmessage='just for tip!'
-
if not self.dirname:
-
self.messageBox=tkMessageBox.showinfo(self.showframe,message=showmessage)
-
self.dirlist=os.listdir(self.entryvar.get())
-
for eachdir in self.dirlist:
-
self.textbox.insert(END,eachdir+'\r\n')
-
self.textbox.update()
-
def refresh(self,event=None):
-
self.textbox.delete('1.0','9999.0')
-
self.dirlist=os.listdir(self.entryvar.get())
-
for eachdir in self.dirlist:
-
self.textbox.insert(END,unicode(eachdir,'cp936')+'\r\n')
-
self.textbox.update()
-
class GuiMenu():
-
def hello(self):
-
pass
-
def File(self):
-
pass
-
def Edit(self):
-
pass
-
def View(self):
-
pass
-
def Help(self):
-
tkMessageBox.showinfo(self.root,u'作者 kinfinger \n verion 1.0 \n Thank you ')
-
def __init__(self,rootmenu):
-
self.root=rootmenu
-
self.menubar=Menu(rootmenu)
-
rootmenu['menu']=self.menubar
-
self.menubar.add_command(label = 'File',command =self.File )
-
self.menubar.add_command(label = 'Edit',command =self.Edit )
-
self.menubar.add_command(label = 'View',command =self.View )
-
self.menubar.add_command(label = 'Help',command =self.Help)
-
def main():
-
root = Tk()
-
topFrame=Frame(root,bg='red')
-
contentFrame=Frame(root,bg='white')
-
bottomFrame=Frame(root,bg='green')
-
topFrame.pack(side=TOP)
-
contentFrame.pack(side=TOP)
-
bottomFrame.pack(side=TOP)
-
GuiMenu(root)
-
fguiChose=FileGuiChose(os.curdir,topFrame,contentFrame,bottomFrame)
-
mainloop()
-
if __name__ == '__main__':
-
main()
ref:
阅读(1787) | 评论(0) | 转发(0) |