简单的界面
2015-10-30 10:54
609 查看
from tkinter import * from tkinter import ttk def test(name,age): return "{} is {} years old.".format(name,age) def func(param): try: result = eval("test("+param+")") except Exception as e: text.insert("3.0","发生错误:{}\n".format(e)) else: text.insert("3.0","{}\n".format(result)) def show(*args): text.insert("1.0","运行开始:\n") param = entry.get() if not param: param = "0" text.insert("2.0","输入参数: {}\n".format(param)) func(param) text.insert("4.0","运行结束.\n") text.insert("5.0","="*50+"\n") root = Tk() root.geometry("400x350+100+100") root.title("测试窗口") entry = ttk.Entry(root,width=40) button = ttk.Button(root,text="Run",command=show) labelframe = ttk.Labelframe(root, text="运行结果") text = Text(labelframe,width=30,height=10) text["wrap"] = "none" text["background"] = "#c1c1c1" s_x = ttk.Scrollbar(labelframe, orient=HORIZONTAL, command=text.xview) v_y = ttk.Scrollbar(labelframe, orient=VERTICAL, command=text.yview) text["xscrollcommand"] = s_x.set text["yscrollcommand"] = v_y.set text.grid(row=0,column=0,sticky="nswe") s_x.grid(row=1,column=0,sticky="we") v_y.grid(row=0,column=1,sticky="ns") labelframe.grid(row=1,column=0,columnspan=2,padx=10,pady=(0,10),sticky="nswe") labelframe.columnconfigure(0,weight=1) labelframe.rowconfigure(0,weight=1) entry.grid(row=0,column=0,pady=(10,0),padx=10) button.grid(row=0,column=1,pady=(10,0),sticky="w") root.rowconfigure(1,weight=1) root.columnconfigure(1,weight=1) entry.focus() root.bind("<Return>",show) root.mainloop()
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法