我有以下代码。当我运行它时,所有内容都按预期运行,但计时器不起作用。我希望工程图的位置可以改变,但不会发生。
# Importing modules
import simpleguitk as sg
import random as rd
# Define global variables
message = "Python is Fun!"
position = [50, 50]
width = 500
height = 500
interval = 2000
# Event handlers
# Handler for message displayed
def new_text(text):
"""Change message displayed"""
global message
message = text
# handler for timer
def tick():
"""Change the posotion"""
global width, height, position
x = rd.randrange(0, width)
y = rd.randrange(0, height)
position[0] = x
position[1] = y
# handler to draw canvas
def draw(canvas):
global message, position
canvas.draw_text(message, position, 16, "purple")
# Create Frame
frame = sg.create_frame("Main Window", width, height)
# Register event handlers
frame.set_draw_handler(draw)
frame.add_input("Enter Message", new_text, 150)
# Set timer
timer = sg.create_timer(interval, tick)
# start frame animation
frame.start()
timer.start()
我的代码有什么问题?请帮助。谢谢。