Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1751704
  • 博文数量: 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-19 21:59:44

          今天继续往下开发的时候,想使用下拉列表,不过悲剧了,发现Tkinter里面竟然没有,你长的丑不是你的错,但是你竟然如此的不健全,哎,想说爱你不容!    不过咱有网络,搜,发现还真有高人写好了组件: Pmw,
然后下载,导入,该包,调试:
import Pmw
ImportError: No module named tkinter
然后发现时,该Pmw是针对3.0,版本的,解决方法:

点击(此处)折叠或打开

  1. import sys,Tkinter
  2. sys.modules['tkinter']=Tkinter
解决了该问题之后,就是使用optionMenu组件,结果发现网上的问题同上次一样,程序如果不运行你还真不知道,会出现什么问题:

点击(此处)折叠或打开

  1. self.dropDownlist = Pmw.OptionMenu(frame,
  2.             #labelpos='w',
  3.             label_text = u'选择关键字:',
  4.             menubutton_textvariable = self.keyvar,
  5.             items = ['BufferPool','Close','Data Change','Compress','Pqty','Sqty'],
  6.             menubutton_width = 10,
  7.         )
发现一旦注释掉该参数,就包错:
TypeError: descriptor 'join' requires a 'str' object but received a 'list'
解决方法就是好好研究官方的DEMO,
紧接着,程序就可以运行,可是,看到界面我真的很是无语,tkinter的组件,although 不是很漂亮,但是也还看的过去,但是,看到这个程序,我真的很无语~~~~~~


下拉列表真是丑陋的一塌糊涂,oooooooo,先休息休息
最新代码如下:

点击(此处)折叠或打开

  1. # -*- coding: cp936 -*-
  2. __author__ = 'kinfinger'
  3. import os
  4. import tkFileDialog
  5. import tkMessageBox
  6. import Pmw
  7. import sys,Tkinter
  8. sys.modules['tkinter']=Tkinter
  9. from Tkinter import *
  10. class FileGuiChose(object):
  11.     def __init__(self,initdir=None,frame=None,showframe=None,bottomFrame=None):
  12.         self.entryvar =StringVar()
  13.         self.showframe=showframe
  14.         # top area
  15.         self.glabel=Label(frame,text=u'你选择的目录为:')
  16.         self.gentry=Entry(frame,textvariable=self.entryvar)
  17.         self.gbutton=Button(frame,command=self.opendir,text=u'选取目录')
  18.         self.keyListBox = Listbox(frame)
  19.         # initiatate the dropdown-list
  20.         self.keyvar=StringVar()
  21.         self.keyvar.set('keyword')
  22.         self.dropDownlist = Pmw.OptionMenu(frame,
  23.             labelpos='w',
  24.             label_text = u'选择关键字:',
  25.             menubutton_textvariable = self.keyvar,
  26.             items = ['BufferPool','Close','Data Change','Compress','Pqty','Sqty'],
  27.             menubutton_width = 10,
  28.         )
  29.         self.gentry.bind('',func=self.refresh)
  30.         self.glabel.grid(row=0,column=0,sticky=W)
  31.         self.gentry.grid(row=0,column=1)
  32.         self.gbutton.grid(row =0,column=2)
  33.         self.dropDownlist.grid(row=0,column=4,sticky=E)
  34.         # content area
  35.         self.textbar=Scrollbar(self.showframe,orient=VERTICAL)
  36.         self.textbar.pack(side=RIGHT,fill=Y)
  37.         # bottome area
  38.         self.bottomBar = Scrollbar(showframe,orient = HORIZONTAL,bg='black')
  39.         self.bottomBar.pack(side=BOTTOM,fill=X)
  40.         self.textbox=Text(self.showframe,yscrollcommand=self.textbar.set,xscrollcommand=self.bottomBar.set,wrap=CHAR)
  41.         self.textbox.pack(side=LEFT,fill=BOTH)
  42.         self.textbar.config(command=self.textbox.yview) # yview
  43.         self.bottomBar.config(command=self.textbox.xview) # xview
  44.     def opendir(self):
  45.         self.textbox.delete('1.0','9999999.0')
  46.         self.dirname=tkFileDialog.askdirectory()
  47.         self.entryvar.set(self.dirname) # related to entry just for show
  48.         showmessage='just for tip!'
  49.         if not self.dirname:
  50.             self.messageBox=tkMessageBox.showinfo(self.showframe,message=showmessage)
  51.         self.dirlist=os.listdir(self.entryvar.get())
  52.         for eachdir in self.dirlist:
  53.             self.textbox.insert(END,eachdir+'\r\n')
  54.         self.textbox.update()
  55.     def refresh(self,event=None):
  56.         self.textbox.delete('1.0','9999999.0')
  57.         self.dirlist=os.listdir(self.entryvar.get())
  58.         for eachdir in self.dirlist:
  59.             self.textbox.insert(END,unicode(eachdir,'cp936')+'\r\n')
  60.         self.textbox.update()
  61. class GuiMenu():
  62.     def hello(self):
  63.         pass
  64.     def File(self):
  65.         pass
  66.     def Edit(self):
  67.         pass
  68.     def View(self):
  69.         pass
  70.     def Help(self):
  71.         tkMessageBox.showinfo(self.root,u'作者 kinfinger \n verion 1.0 \n Thank you \n kinfinge@gmail.com ')
  72.     def __init__(self,rootmenu):
  73.         self.root=rootmenu
  74.         self.menubar=Menu(rootmenu)
  75.         # create a pulldown menu, and add it to the menu bar
  76.         filemenu = Menu(self.menubar, tearoff=0)
  77.         filemenu.add_command(label="Open", command=self.File)
  78.         filemenu.add_command(label="New", command=self.File)
  79.         filemenu.add_command(label="Save", command=self.File)
  80.         filemenu.add_separator()
  81.         filemenu.add_command(label="Exit", command=rootmenu.quit)
  82.         self.menubar.add_cascade(label="File", menu=filemenu)
  83.         # create more pulldown menus
  84.         editmenu = Menu(self.menubar, tearoff=0)
  85.         editmenu.add_command(label="Cut", command=self.Edit)
  86.         editmenu.add_command(label="Copy", command=self.Edit)
  87.         editmenu.add_command(label="Paste", command=self.Edit)
  88.         self.menubar.add_cascade(label="Edit", menu=editmenu)
  89.         helpmenu = Menu(self.menubar,tearoff=0)
  90.         helpmenu.add_command(label="About", command=self.Help)
  91.         self.menubar.add_cascade(label="Help", menu=helpmenu)
  92.         rootmenu.config(menu=self.menubar)
  93. def main():
  94.     root = Tk()
  95.     root.title('DDL Check')
  96.     root.columnconfigure(0,minsize=50)
  97.     topFrame=Frame(root,height=80)
  98.     contentFrame=Frame(root,bg='white')
  99.     bottomFrame=Frame(root,bg='green')
  100.     topFrame.pack(side=TOP)
  101.     contentFrame.pack(side=TOP)
  102.     bottomFrame.pack(side=TOP)
  103.     GuiMenu(root)
  104.     fguiChose=FileGuiChose(os.curdir,topFrame,contentFrame,bottomFrame)
  105.     mainloop()
  106. if __name__ == '__main__':
  107.     main()

PS: 
今天涉及的组件主要有: 
menu ,optionMenu,TopLevel widget,模块重命名

ref:

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