python核心编程-GUI程序之偏函数应用
2016-01-22 22:46
716 查看
#!/usr/bin/env python # -*- coding: UTF-8 -*- from functools import partial as pto from Tkinter import Tk, Button, X from tkMessageBox import showinfo, showwarning WARN = 'warn' CRIT = 'crit' REGU = 'regu' SIGNS = { 'do not enter': CRIT, 'railroad 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 Pressond!') 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='goldenrod1') 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()') print cmd eval(cmd) top.mainloop()
输出:
相关文章推荐
- 《笨办法学Python》 第20课手记
- python核心编程-GUI程序之标签,按钮,进度条
- python操作RabbiMQ
- python核心编程-GUI程序按钮与标签
- Python 格式化字符分类
- Python操作MySQL数据库
- python模块系列之 - copy
- python--datetime&time
- [Python]Python pip用国内镜像下载的办法
- Python标准库:内置函数dict(**kwarg)
- 用Python操纵MySQL
- Python工具之SQLAlchemy
- 【LEETCODE】81-Search in Rotated Sorted Array II [Python]
- Python中urllib2总结
- python 中导入自己定义的模块路径
- python爬hdu网页
- Python学习笔记——基础篇(1): 变量及其类型
- python自动化渗透
- Python下载大全
- Python 高级特性之 sorted( )