匿名用户
1级
2015-06-30 回答
#!/usr/bin/env python
# Filename: appui.py
"""
.. moduleauthor:: ....
.. test module of Tkinter
"""
from Tkinter import *
import tkMessageBox
root = Tk()
root.geometry('850x40+80+80') #设置窗体高宽与窗体相对屏幕左上角位置
class Appui(Frame):
"""
docsting for Appui
"""
def __init__(self, parent=None):
"""
Initialize the Appui Class
"""
Frame.__init__(self, width=850, height=60, bg='gray40')
self.propagate(False)
self.pack()
self.input = StringVar()
self.master.title('Test Widgets')
self.master.iconname('Tk-42')
self.buildFrame() # Build the widgets
def buildFrame(self):
"""
make the frame and add widgets into the frame
"""
self.LabelF=Frame(self,width=850, height=60, bg='gray80')
self.LabelF.propagate(False)
self.LabelF.pack(side=TOP)
Label(self.LabelF, fg='steelblue1', bg='gray80', text= "Text field description: ").pack(side=LEFT)
#设置输入的widgets
self.e0 = Entry(self.LabelF, width=80, textvariable=self.input)
self.e0.pack(side=LEFT)
Button(self.LabelF, text='Get', borderwidth=5, command=self.callback).pack(side=RIGHT,padx=10)
def callback(self):
"""
callback of get path Button
"""
try:
#self.e0.delete(0,END)
Value=self.input.get()
if Value is not None:
print "Get String from Entry" + Value
else:
self.e0.delete(0,END)
except (RuntimeError, TypeError, NameError, ValueError, IOError) as e:
tkMessageBox.showerror("Error function callback()", '%s' % e)
def exit(self):
"""
exit of process
"""
exit(0)
def main():
"""
Main function
"""
Appui().mainloop()
if __name__ == '__main__':
main()