2019独角兽企业重金招聘Python工程师标准>>>
'''
Created on 2012-9-19
@author: liangqianwu
'''
#_*_ coding:utf-8_*_
from Tkinter import *
def frame(root,side):
w=Frame(root)
w.pack(side=side,fill=BOTH)
return w
def button(root,side,text,command=None):
w=Button(root,text=text,command=command)
w.pack(side=side,expand=YES,fill=BOTH)
return w
def ShowMessage(root,text,relief=GROOVE,padx=10,pady=10):
Message(root,text=text,relief=relief).pack(padx=padx,pady=pady)
def makeCommandMenu(root,text,side=LEFT,underline=0,padx=0,pady=0):
CmdBtn=Menubutton(root,text=text,underline=underline)
CmdBtn.pack(side=side,padx='2m')
CmdBtn.menu=Menu(CmdBtn)
CmdBtn.menu.add_command(label='Undo')
CmdBtn.menu.entryconfig(0,state=DISABLED)
CmdBtn.menu.add_command(label='New',underline=0,command=lambda r=root:ShowMessage(r,'select New'))
CmdBtn.menu.add_command(label='Open',underline=0)
CmdBtn.menu.add_command(label='Quit',underline=0,background='white',activebackground='green',command=CmdBtn.quit)
CmdBtn['menu']=CmdBtn.menu
return CmdBtn
def makeCascadeMenu(root,text,side=LEFT,underline=0,padx=0,pady=0):
CasBtn=Menubutton(root,text=text,underline=underline)
CasBtn.pack(side=side,padx='2m')
CasBtn.menu=Menu(CasBtn)
CasBtn.menu.choices=Menu(CasBtn.menu)
CasBtn.menu.choices.wieerdones=Menu(CasBtn.menu.choices)
CasBtn.menu.choices.wieerdones.add_command(label='Stockbroker')
CasBtn.menu.choices.wieerdones.add_command(label='Quantity Surveyor')
CasBtn.menu.choices.wieerdones.add_command(label='Church Warden')
CasBtn.menu.choices.wieerdones.add_command(label='BRM')
CasBtn.menu.choices.add_command(label='Wooden Leg')
CasBtn.menu.choices.add_command(label='Hire Purchase')
CasBtn.menu.choices.add_command(label='Dead Creb')
CasBtn.menu.choices.add_command(label='Tree Surggeon')
CasBtn.menu.choices.add_cascade(label='Is it a...',menu=CasBtn.menu.choices.wieerdones)
CasBtn.menu.add_cascade(label='Scipts',menu=CasBtn.menu.choices)
CasBtn['menu']=CasBtn.menu
return CasBtn
def makeCheckbuttonMenu(root,text,side=LEFT,underline=0,padx=0,pady=0):
ChkBtn=Menubutton(root,text=text,underline=underline)
ChkBtn.pack(side=side,padx='2m')
ChkBtn.menu=Menu(ChkBtn)
ChkBtn.menu.add_checkbutton(label='Doug')
ChkBtn.menu.add_checkbutton(label='Dinsdale')
ChkBtn.menu.add_checkbutton(label='Stig o ')
ChkBtn.menu.add_checkbutton(label='Vince')
ChkBtn.menu.add_checkbutton(label='Gloria Pules')
ChkBtn.menu.invoke(ChkBtn.menu.index('Dinsdale'))
ChkBtn['menu']=ChkBtn.menu
return ChkBtn
def makeRadiobuttonMenu(root,text,side=LEFT,underline=0,padx=0,pady=0):
RadBtn=Menubutton(root,text=text,underline=underline)
RadBtn.pack(side=side,padx='2m')
RadBtn.menu=Menu(RadBtn)
RadBtn.menu.add_radiobutton(label='metonymy')
RadBtn.menu.add_radiobutton(label='zeugmatists')
RadBtn.menu.add_radiobutton(label='synechdotists')
RadBtn.menu.add_radiobutton(label='axiomists')
RadBtn.menu.add_radiobutton(label='anagogists')
RadBtn.menu.add_radiobutton(label='catachresis')
RadBtn.menu.add_radiobutton(label='periphrastic')
RadBtn['menu']=RadBtn.menu
return RadBtn
def makeDisabledMenu(root,text,side=LEFT,underline=0,padx=0,pady=0):
Dummy_button=Menubutton(root,text=text,underline=underline)
Dummy_button.menu=Menu(Dummy_button)
class Calculator(Frame):
def __init__(self):
Frame.__init__(self,borderwidth=2,width=200,height=110)
self.pack(fill=BOTH)
self.master.title('hello Menu')
self.master.iconname('calcl')
opsF=frame(self,TOP)
CmdBtn=makeCommandMenu(opsF,'Button Commands')
CasBtn=makeCascadeMenu(opsF,'Cascading Menus')
ChkBtn=makeCheckbuttonMenu(opsF,'check Menus')
RadBtn=makeRadiobuttonMenu(opsF,'Radiobutton Menus')
NoBtn=makeDisabledMenu(opsF,'NoBtn')
opsF.tk_menuBar(CmdBtn,ChkBtn,RadBtn,NoBtn)
Label(self,text='''hello my name is liang '''+
'''What are your name'''+
'''I love you ''').pack(side=BOTTOM)
if __name__ =='__main__':
Calculator().mainloop()