发布时间:2019-09-13 09:25:16编辑:auto阅读(1745)
A good program design principle:
I have an update handler that handles changing the message, and例1 Simple "screensaver" program
# Import modules
import simplegui
import random
# Global state
message = "Python is Fun!"
position = [50, 50]
width = 500
height = 500
interval = 2000
# Handler for text box
def update(text):
global message
message = text
# Handler for timer
def tick():
x = random.randrange(0, width)
y = random.randrange(0, height)
position[0] = x
position[1] = y
# Handler to draw on canvas
def draw(canvas):
canvas.draw_text(message, position, 36, "Red")
# Create a frame
frame = simplegui.create_frame("Home", width, height)
# Register event handlers
text = frame.add_input("Message:", update, 150)
frame.set_draw_handler(draw)
timer = simplegui.create_timer(interval, tick)
# Start the frame animation
frame.start()
timer.start()
#下面这样改可以吗?
import simplegui
def timer_handler():
print "timer called"
timer = simplegui.create_timer(50, timer_handler)
timer.start()
timer = simplegui.create_timer(1000, timer_handler)
timer.start()
上面代码中,timer的interval企图从50 milisecond变化为1second(1000 milisecond)。…
timer.stop()
timer = simplegui.create_timer(1000, timer_handler)
timer.start()
上一篇: python 捕捉和模拟鼠标键盘操作
下一篇: python 初探状态机transiti
47615
46003
36918
34483
29093
25738
24577
19723
19261
17764
5579°
6164°
5699°
5755°
6717°
5494°
5498°
5998°
5972°
7304°