Python 官方文档:入门教程 => 点击学习
下面的笔记内容来自coursera上的python公开课。 A Good program design principle: I have an u
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()
--结束END--
本文标题: Python学习笔记(5)Timer
本文链接: https://www.lsjlt.com/news/189574.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0