Python GUI
1. 事件驱动
一个事件及其回调的例子是鼠标移动。我们假设鼠标指针停在您GUI 程序的某处。如果鼠标被移到了程序的别处,一定是有什么东西引起了屏幕上指针的移动,从而表现这种位置的转移。系统必须处理这些鼠标移动事件才能展现(并实现)鼠标在窗口上的移动。一旦您释放了鼠标,就不再会有事件需要处理,相应地,屏幕上的一切又复归平静。然后API又在这个鼠标事件上封装一层。
一旦进入主循环,GUI 便从此掌握控制权。所有其他动作都来自回调函数,包括程序退出。
2. 默认值的智慧
GUI 开发从Python 的缺省参数机制获益匪浅,因为Tkinter 组件有大量的默认动作。除非您熟知自己使用的每一个组件的每一个可用选项,否则最好只设置您关心的参数而把其他的交由系统处理。这些缺省值是精心选出的。如果您没有提供这些值也不必担心程序会在屏幕上表现怪异。作为一条基本规则,程序都由一系列经优化的缺省值创建,并且只有当您明确知道如何配置您的组件时,才有必要用自己的值替换这些缺省值。
相关文档:
源代码下载:下载地址在这里
# 033
class Person:
age = 22
def sayHello(self): # 方法与函数的区别在于需要一个self参数
print 'Hello!'
# end of def
# end of class # 这是我良好的编程风格
p = Person()
print p.age
p.sayHello()
output:
22
Hello! ......
源代码下载:下载地址在这里
# 037
fileName = ''
while 1:
fileName = raw_input("Input a file name:")
if fileName == 'q':
break
try:
f = file(fileName, 'r')
print 'Opened a file.'
except:
print 'There is no file named', fileName
......
# 040
import time
try:
f = file('040_Finally.py')
while True:
line = f.readline()
if len(line) == 0:
break
time.sleep(0.33)
print line,
# end of while
finally:
f.close()
print 'Closed the file.'
# end of try
output:
> ......
可以播放大部分的音视频.
demo download: http://www.sandy1219.com/python/media.rar
playMP3.py
# -*- coding: utf-8 -*-
import wx;
import wx.media;
import os;
import SPrint;
import mediaStateBar;
import mediaList;
import SaveLog;
import MediaItem;
woldcart = "media files|*.*|avi ......
ZoundryDocument
Python skin is known for its color variations and for its elasticity; it is
the warmest leather of the season and ideal for the manufacture of many luxury
goods. Sometimes natural patterns can be hidden when they're done in black, but
the finish here has a bit of a shine to it ......