本文整理汇总了Python中Grid.Grid.restart方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.restart方法的具体用法?Python Grid.restart怎么用?Python Grid.restart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grid.Grid
的用法示例。
在下文中一共展示了Grid.restart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import restart [as 别名]
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.running = True
self.grid()
self.create_widgets(master)
self.grid = Grid(self.canvas, 40)
self.val = 0
self.draw_every_steps = 1
self.draw_step = 0
master.after(100, self.animation)
def create_widgets(self, master):
self.btn_start = Button(self, text = "Start")
self.btn_start["text"] = "Start"
self.btn_start["command"] = self.start
self.btn_start.grid()
self.btn_stop = Button(self)
self.btn_stop["text"] = "Stop"
self.btn_stop["command"] = self.stop
self.btn_stop.grid()
self.btn_stop = Button(self)
self.btn_stop["text"] = "Restart"
self.btn_stop["command"] = self.restart
self.btn_stop.grid()
self.canvas = Canvas(master, height = 400, width = 500, bg="white")
self.canvas.pack()
self.canvas.grid()
def start(self):
self.running = True
def stop(self):
self.running = False
def restart(self):
self.grid.restart()
self.running = True
def animation(self):
if self.running == True:
self.grid.step_all()
self.draw_step += 1
if(self.draw_step >= self.draw_every_steps):
self.draw_step = 0
self.grid.draw()
self.master.after(1, self.animation)