本文整理汇总了Python中timer.Timer.updateClock方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.updateClock方法的具体用法?Python Timer.updateClock怎么用?Python Timer.updateClock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.updateClock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import updateClock [as 别名]
class Beings:
def __init__(self, main): # cnfbtn, world, predCount, preyCount, sbtn, bbox, bbox1, timelbl, main):
'''args world (eg Canvas object), predCount and preyCount, initiates life process when live is called in pain loop
'''
self.world = main.world
self.world.state = {'state' : 'inactive'}
self.main = main
#get configuration
self.config = WorldConfiguration()
self.deadPredators = list()
self.deadPrey = list()
self.tags = list()
#stop button and being box for binding after live() is called
self.sbtn = main.sbtn
self.bbox = main.bbox
self.bbox1 = main.bbox1
self.timelbl = main.timelbl
def configure(self):
self.conf = Toplevel()
self.conf.wm_title("Configure Universe")
self.reconfig = self.config.reconfigure(self)
def live(self):
#set the state to active and clear the canvas of all attributes
self.predators = [Predator(self) for i in range(self.config.predCount)]
self.prey = [Prey(self) for i in range(self.config.preyCount)]
self.beings = list(self.predators + self.prey)
self.world.state['state'] = 'active'
self.world.delete("all")
for being in self.beings:
if being.type == 'predator':
being.tag = self.world.create_rectangle(being.genX, being.genY, being.genX+10, being.genY-10, fill=being.color)
else:
being.tag = self.world.create_oval(being.genX, being.genY, being.genX+10, being.genY-10, fill=being.color)
#start session thread
self.stopThread = False
self.session = Thread(target=self.activate)
self.session.start()
#bind the Thread object _Thread__stop() method to the stop button
self.sbtn.config(command=self.threadStop)
def threadStop(self):
self.stopThread = True
self.session = None
def activate(self):
#instantiate timer and pass in timerlbl
self.timer = Timer(self.timelbl)
#bind showInfo to each being
lambda x: self.world.tag_bind(x.tag,"<ButtonPress-1>", x.showInfo), self.beings
while self.stopThread == False:
#move each being
map(lambda x: self.move(x), self.beings)
#predators hunt!
for pred in self.predators:
pred.hunt(self.prey, self.world, self)
pred.kill(self.world, self.prey, self.deadPrey, self.beings)
#age the beings
for being in self.beings:
being.age(self)
#update the clock
self.timer.updateClock()
#update being box
self.bbox.delete(1.0, END)
bboxstr = "Predators \n"
for pred in self.predators:
if pred.target:
bboxstr += "tag-%s; vR-%s; kR-%s; kC-%s; lfe-%s tgt-%s\n" % (pred.tag, pred.visionRange, pred.killRange, pred.killCount, pred.curLife, pred.target.tag)
else:
bboxstr += "tag-%s; vR-%s; kR-%s; kC-%s; lfe-%s tgt-%s\n" % (pred.tag, pred.visionRange, pred.killRange, pred.killCount, pred.curLife, "None")
bboxstr += "#pred-%s #prey-%s #beings=%s\nDead Predators:\n" % (len(self.predators), len(self.prey), len(self.beings))
for pred in self.deadPredators:
bboxstr += "tag-%s; vR-%s, kR-%s; kC-%s\n" % (pred.tag, pred.visionRange, pred.killRange, pred.killCount)
self.bbox.insert("1.0", bboxstr)
#check to ensure game is not over
if len(self.predators) == 0 or len(self.prey) == 0:
self.threadStop()
#.........这里部分代码省略.........