运用PFA的路灯指示牌GUI程序
生活随笔
收集整理的這篇文章主要介紹了
运用PFA的路灯指示牌GUI程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
#!/usr/bin/python2.7from 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,
'railroad crossing':WARN,
'55\nspeed limit':REGU,
'wrong way':CRIT,
'merging traffic':WARN,
'one way':REGU
?????? }
critCB=lambda:showerror('Error','Error Button Pressed')
warnCB=lambda:showwaining('Warning','Warning Button Pressed')
infoCB=lambda:showinfo('Info','Info Button Pressed')
top=Tk()
top.title('Road Signs')
Button(top,text='QUIT',command=top.quit,bg='red',fg='white').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_r(cmd)
top.mainloop()
運行:
#!/usr/bin/python2.7from functools import partial as pto from Tkinter import Tk,Button,X from tkMessageBox import showinfo,showwarning,showerrorWARN='warn' CRIT='crit' REGU='regu'SIGNS={ 'do not enter':CRIT, 'railroad crossing':WARN, '55\nspeed limit':REGU, 'wrong way':CRIT, 'merging traffic':WARN, 'one way':REGU}critCB=lambda:showerror('Error','Error Button Pressed') warnCB=lambda:showwaining('Warning','Warning Button Pressed') infoCB=lambda:showinfo('Info','Info Button Pressed')top=Tk() top.title('Road Signs') Button(top,text='QUIT',command=top.quit,bg='red',fg='white').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_r(cmd) top.mainloop()運行:
轉載于:https://my.oschina.net/annieduoduo/blog/71403
總結
以上是生活随笔為你收集整理的运用PFA的路灯指示牌GUI程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么程序员不擅长估算时间
- 下一篇: Asp.net Web API实战