python Tkinter的学习笔记
2012-09-23 21:02
363 查看
周末在家学习了python的Tkinter,感觉这东西简单好用。
出来的效果:
# !/usr/bin/env python # coding=utf-8 from Tkinter import * import ttk import tkMessageBox filename = 'test.txt' def defocus(event): event.widget.master.focus_set() def DisplayHello(event): # win = Toplevel() # Label(win,text='Hello, Tkinter').pack(pady=15) # tkMessageBox.showinfo('Response','Thanks for clicking the button.') tkMessageBox.askquestion('MSG', '要保存吗?',savefile) root =Tk(className="main") def savefile(event): textfile = open(filename, 'a') #for how to solve chinese coding, see #http://flyantme.blog.163.com/blog/static/7586977520096711026111/ first = txtfirst.get().encode('utf-8') last = txtlast.get().encode('utf-8') address = txtadd.get().encode('utf-8') city = txtcity.get().encode('utf-8') state = txtst.get().encode('utf-8') zipcode = txtzip.get().encode('utf-8') phone = txtph.get().encode('utf-8') email = txtemail.get().encode('utf-8') step = comboBox1.get().encode('utf-8') print >> textfile, last, '\n', first, '\n', address, '\n', city, '\n', state, '\n', zipcode, '\n', phone, '\n', step, '\n',email textfile.close() # root.destroy() root.geometry('500x300+400+400') root.maxsize(500, 300) root.minsize(500, 300) d = Frame(root) fname = Label(d, width = 10,text = u'ip') fname.pack(side = 'left',fill ='x', pady = 1) txtfirst = Entry(d, width =40) txtfirst.pack(side = 'left') d.pack(side = 'top',fill ='x',pady = 1) #d.place(x =0, y =0, anchor = NW) e = Frame(root) lname = Label(e, width = 10,text = u'姓') lname.pack(side = 'left',pady = 1) txtlast = Entry(e, width =40) txtlast.pack(side = 'left') e.pack(side = 'top',fill ='x',pady = 1) f = Frame(root) address = Label(f, width = 10,text = u'街道') address.pack(side = 'left',pady = 1) txtadd = Entry(f, width =40) txtadd.pack(side = 'left') f.pack(side = 'top',fill ='x') g = Frame(root) city = Label(g, width = 10,text = u'市') city.pack(side = 'left',pady = 1) txtcity = Entry(g, width =16) txtcity.pack(side = 'left') street = Label(g, width = 10,text = u'省') street.pack(side = 'left',pady = 1) txtst = Entry(g, width =4) txtst.pack(side = 'left') zipcde = Label(g, width = 10,text = u'邮政编码') zipcde.pack(side = 'left',pady = 1) txtzip = Entry(g, width =8) txtzip.pack(side = 'left') g.pack(side = 'top',fill ='x') h = Frame(root) phone = Label(h, width = 10,text = u'电话') phone.pack(side = 'left',pady = 1) txtph = Entry(h, width =16) txtph.pack(side = 'left') email = Label(h, width = 10,text = 'E-mail') email.pack(side = 'left',pady = 1) txtemail = Entry(h, width =16) txtemail.pack(side = 'left') h.pack(side = 'top',fill ='x') x = Frame(root) phone = Label(x, width = 10,text = u'Step1') phone.pack(side = 'left',pady = 1) comboBox1 = ttk.Combobox(x, state="readonly", values=("a", "b", "c",""),width = 26) comboBox1.pack(side = 'left') comboBox1.set("") comboBox1.bind("<FocusIn>", defocus) x.pack(side = 'top',fill ='x',pady = 1) y = Frame(root) phone = Label(y, width = 10,text = u'Step2') phone.pack(side = 'left',pady = 1) comboBox = ttk.Combobox(y, state="readonly", values=("a", "b", "c",""),width = 26) comboBox.pack(side = 'left') comboBox.set("") comboBox.bind("<FocusIn>", defocus) y.pack(side = 'top',fill ='x',pady = 1) j=Frame(root) save = Button(j, text = u"保存", width = 10) save.pack(pady=1, padx =30) save.bind("<Button-1>", savefile) #save.bind("<Button-1>", DisplayHello) j.pack(side='left',fill='y') i = Frame(root) close = Button(i, text = u"取消",command=root.destroy) close.pack(side = 'left',pady = 1, padx = 50) i.pack(side = 'top',fill ='x') root.mainloop()
出来的效果:
相关文章推荐
- python学习笔记之tkinter中的label
- python Tkinter学习笔记 简单的计算器 03
- python学习笔记——Tkinter GUI编程——简介
- Python学习笔记 GUI-Tkinter
- Python Tkinter 学习笔记(一) Hello world
- Python:GUI之tkinter学习笔记2界面布局显示
- Python 【Tkinter 常用控件】 学习笔记
- Python学习笔记_02:使用Tkinter连接MySQL数据库实现登陆注册功能
- python学习笔记_Tkinter
- Python:GUI之tkinter学习笔记1控件的介绍及使用
- python tkinter 学习笔记(1)
- python学习笔记——Tkinter GUI编程——简介
- Python:GUI之tkinter学习笔记3事件绑定
- python Tkinter学习笔记 基础UI控件 01
- python Tkinter学习笔记 menu控件 02
- Python:GUI之tkinter学习笔记之messagebox、filedialog
- Python Tkinter 学习笔记(二)Hello_again
- Python学习笔记--Tkinter制作GUI
- Python模块学习笔记— —random
- Python学习笔记(三)windows下安装theano