运用PFA的路灯指示牌GUI程序

#!windows python2.7

from functools import partial as pto
from Tkinter import Tk,Button,X
from tkMessageBox import showinfo,showwarning,showerror

WARN='warn'
CRIT='crit'
REGU='regu'

SIGNS={
    'do not enter':CRIT,
    'railload crossing':WARN,
    '55\nspeed limit':REGU,
    'merging traffic':WARN,
    'one way':REGU
    }

critCB=lambda:showerror('Error','Error Button Pressed')
warnCB=lambda:showwarning('Warning','Warning Button Pressed')
infoCB=lambda:showinfo('Info','Info Button Pressed')

top=Tk()
top.title('Road Signs')
quit = Button(top,text='QUIT',command=top.quit,bg='red',fg='white')
quit.pack()

MyButton=pto(Button,top)
CritButton=pto(MyButton,command=critCB,bg='white',fg='red')
WarnButton=pto(MyButton,command=warnCB,bg='blue')
ReguButton=pto(MyButton,command=infoCB,bg='white')

for eachSign in SIGNS:
       signType=SIGNS[eachSign]
       cmd='%sButton(text=%r%s).pack(fill=X, expand=True)'%(signType.title(),eachSign, '.upper()'if signType==CRIT  else '.title()')
       eval(cmd)

top.mainloop()

你可能感兴趣的:(运用PFA的路灯指示牌GUI程序)