我有一个简单的代码来使用tkinter可视化一些数据.按钮单击绑定到重绘下一个"数据帧"的函数.但是,我想选择以特定频率自动重绘.在GUI编程方面我非常环保(我不需要为这段代码做很多事情),因此我的大多数tkinter知识来自跟随和修改示例.我想我可以使用root.after来实现这一点,但我不太清楚我是否理解其他代码.我的程序的基本结构如下:
# class for simulation data
# --------------------------------
def Visualisation:
def __init__(self, args):
# sets up the object
def update_canvas(self, Event):
# draws the next frame
canvas.delete(ALL)
# draw some stuff
canvas.create_........
# gui section
# ---------------------------------------
# initialise the visualisation object
vis = Visualisation(s, canvasWidth, canvasHeight)
# Tkinter initialisation
root = Tk()
canvas = Canvas(root, width = canvasWidth, height = canvasHeight)
# set mouse click to advance the simulation
canvas.grid(column=0, row=0, sticky=(N, W, E, S))
canvas.bind('<Button-1>', vis.update_canvas)
# run …Run Code Online (Sandbox Code Playgroud)