免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2499 | 回复: 0
打印 上一主题 下一主题

python图形编程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-18 23:21 |只看该作者 |倒序浏览

                第一个:最简单的也是最经典的程序helloworld
1 #!/usr/bin/env python
2 import Tkinter#导入tk库
3 top=Tkinter.Tk()#建立主窗口
4 label=Tkinter.Label(top,text='hello world!!')#标签组件
5 label.pack()#封装标签
6 Tkinter.mainloop()#事件循环
第二个:设置背景及字体颜色
1 #!/usr/bin/env python
2 import Tkinter#导入tk库
3 top=Tkinter.Tk()#建立主窗口
4 label=Tkinter.Label(top,text='hello world!!',bg=’red’,fg=’green’)#标签组件,bg背景色,fg字体颜色
5 label.pack()#封装标签
6 Tkinter.mainloop()#事件循环
第三个:加入按钮组件,并将背景色设置为黑色。
  1 #!/usr/bin/env python
  2 import Tkinter
  3 top=Tkinter.Tk()
  4 quit=Tkinter.Button(top,text='hello world!!\n',command=top.quit,bg='black')
  5 quit.pack()
  6 label=Tkinter.Label(top,text='hello world!\n!')
  7 label.pack()
  8 Tkinter.mainloop()
第四个:应用框架
  1 import Tkinter
  2 from Tkconstants import *
  3
  4 top = Tkinter.Tk()
  5
  6 hello = Tkinter.Label(top, text='Hello World!',bg='green',fg='blue')
  7 hello.pack()
  8
  9 frame = Tkinter.Frame(top, relief=RIDGE, borderwidth=2,bg='yellow')
10
11 frame.pack(fill=BOTH,expand=1)
12
13 label = Tkinter.Label(frame, text="Hello, World",fg='green')
14 label.pack(fill=X, expand=1)
15
16 button = Tkinter.Button(frame,text="Exit",command=top.destroy,bg='blue')
17 button.pack(side=BOTTOM)
18
19
20quit=Tkinter.Button(top, text='QUIT',command=top.quit, activeforeground='w hite',activebackground='red')#鼠标未放上之前白色,放上之后红色
21 quit.pack(fill=Tkinter.X, expand=1)
22
23 Tkinter.mainloop()
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/73535/showart_1423157.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP