可以做单的猎头网站,怎么制作网页表格,公司官网网址,资源分享论坛wordpressPython可用的GUI编程的包很多#xff0c;Tkinter也是其中一个半标准的工具包。作为一个老牌的Python GUI工具包(皮皮书屋里找了本书#xff0c;竟然是2001年的),它由Tk GUI包装而来。在Windows版里面已经包括了#xff0c;不用单独下载。用Tkinter实现一个简单的GUI程序,单击…Python可用的GUI编程的包很多Tkinter也是其中一个半标准的工具包。作为一个老牌的Python GUI工具包(皮皮书屋里找了本书竟然是2001年的),它由Tk GUI包装而来。在Windows版里面已经包括了不用单独下载。用Tkinter实现一个简单的GUI程序,单击click按钮时会在终端打印出’hello world’__author__ fybyfrom Tkinter import * #引入Tkinter工具包defhello():print(hello world!)win Tk() #定义一个窗体win.title(Hello World) #定义窗体标题win.geometry(400x200) #定义窗体的大小是400X200像素btn Button(win, textClick me, commandhello)#注意这个地方不要写成hello(),如果是hello()的话#会在mainloop中调用hello函数#而不是单击button按钮时出发事件btn.pack(expandYES, fillBOTH) #将按钮pack充满整个窗体(只有pack的组件实例才能显示)mainloop()#进入主循环程序运行当我们写一个较大的程序时最好将代码分成一个或者是几个类再看一下Hello World例子#-*- encodingUTF-8 -*-__author__ fybyfrom Tkinter import *classApp:def __init__(self, master):#构造函数里传入一个父组件(master),创建一个Frame组件并显示frame Frame(master)frame.pack()#创建两个button并作为frame的一部分self.button Button(frame, textQUIT, fgred, commandframe.quit)self.button.pack(sideLEFT) #此处side为LEFT表示将其放置 到frame剩余空间的最左方self.hi_there Button(frame, textHello, commandself.say_hi)self.hi_there.pack(sideLEFT)defsay_hi(self):print hi there, this is a class example!winTk()appApp(win)win.mainloop()看完了上面两个无聊的Hello World例子再来看一个稍微Perfect点的东西吧。Menu组件自己画一个像样点的程序外壳。#-*- encodingUTF-8 -*-__author__ fybyfrom Tkinter import *rootTk()defhello():print(hello)#创建一个导航菜单menubar Menu(root)menubar.add_command(labelHello!, commandhello)menubar.add_command(labelQuit!,commandroot.quit)root.config(menumenubar)mainloop()这个程序还是有点无趣因为我们只是创建了一个顶级的导航菜单点击后只是在终端中输出hello而已下面来创建一个下拉菜单这样才像一个正儿八经的应用在下面的这个例子中会创建三个顶级菜单每个顶级菜单中都有下拉菜单(用add_command方法创建最后用add_cascade方法加入到上级菜单中去)为每个下拉选项都绑定一个hello函数在终端中打印出hello.root.quit是退出这个Tk的实例。#-*- encodingUTF-8 -*-__author__ fybyfrom Tkinter import *rootTk()defhello():print(hello)defabout():print(我是开发者)menubarMenu(root)#创建下拉菜单File然后将其加入到顶级的菜单栏中filemenu Menu(menubar,tearoff0)filemenu.add_command(labelOpen, commandhello)filemenu.add_command(labelSave, commandhello)filemenu.add_separator()filemenu.add_command(labelExit, commandroot.quit)menubar.add_cascade(labelFile, menufilemenu)#创建另一个下拉菜单Editeditmenu Menu(menubar, tearoff0)editmenu.add_command(labelCut, commandhello)editmenu.add_command(labelCopy, commandhello)editmenu.add_command(labelPaste, commandhello)menubar.add_cascade(labelEdit,menueditmenu)#创建下拉菜单Helphelpmenu Menu(menubar, tearoff0)helpmenu.add_command(labelAbout, commandabout)menubar.add_cascade(labelHelp, menuhelpmenu)#显示菜单root.config(menumenubar)mainloop()写了这一些差不多对Tkinter有了一个大体的印象了。在Python中用Tkinter绘制GUI界面还是蛮简单的。再把上面的例子扩展一下和Label标签结合当单击about的时候在窗体上打印About的内容而不是在终端输出。将about函数稍微修改一下。单击about以后将会调用about函数渲染frame绘制一个标签并显示其内容。defabout():w Label(root,text开发者感谢名单\nfuyunbiyi\nfyby尚未出现的女朋友\nhttp://www.programup.com网站)w.pack(sideTOP)