本文整理汇总了Python中stopwatch.Stopwatch.display方法的典型用法代码示例。如果您正苦于以下问题:Python Stopwatch.display方法的具体用法?Python Stopwatch.display怎么用?Python Stopwatch.display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stopwatch.Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.display方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StopwatchApplication
# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import display [as 别名]
class StopwatchApplication(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
# Initialize widgets
self.create_widgets()
# Create a Stopwatch interpreter
with open('stopwatch_external.yaml') as f:
statechart = import_from_yaml(f)
# Create a stopwatch object and pass it to the interpreter
self.stopwatch = Stopwatch()
self.interpreter = Interpreter(statechart,
initial_context={'stopwatch': self.stopwatch},
initial_time=time.time())
# Run the interpreter
self.run()
# Update the stopwatch every 100ms
self.after(100, self.update_stopwatch)
def update_stopwatch(self):
self.stopwatch.update(delta=0.1)
self.after(100, self.update_stopwatch)
# Update timer label
self.w_timer['text'] = self.stopwatch.display()
def run(self):
# Queue a call every 100ms on tk's mainloop
self.interpreter.execute()
self.after(100, self.run)
self.w_states['text'] = 'active states: ' + ', '.join(self.interpreter.configuration)
def create_widgets(self):
self.pack()
# Add buttons
self.w_btn_start = tk.Button(self, text='start', command=self._start)
self.w_btn_stop = tk.Button(self, text='stop', command=self._stop)
self.w_btn_split = tk.Button(self, text='split', command=self._split)
self.w_btn_unsplit = tk.Button(self, text='unsplit', command=self._unsplit)
self.w_btn_reset = tk.Button(self, text='reset', command=self._reset)
self.w_btn_quit = tk.Button(self, text='quit', command=self._quit)
# Initial button states
self.w_btn_stop['state'] = tk.DISABLED
self.w_btn_unsplit['state'] = tk.DISABLED
# Pack
self.w_btn_start.pack(side=tk.LEFT,)
self.w_btn_stop.pack(side=tk.LEFT,)
self.w_btn_split.pack(side=tk.LEFT,)
self.w_btn_unsplit.pack(side=tk.LEFT,)
self.w_btn_reset.pack(side=tk.LEFT,)
self.w_btn_quit.pack(side=tk.LEFT,)
# Active states label
self.w_states = tk.Label(root)
self.w_states.pack(side=tk.BOTTOM, fill=tk.X)
# Timer label
self.w_timer = tk.Label(root, font=("Helvetica", 16), pady=5)
self.w_timer.pack(side=tk.BOTTOM, fill=tk.X)
def _start(self):
self.interpreter.queue(Event('start'))
self.w_btn_start['state'] = tk.DISABLED
self.w_btn_stop['state'] = tk.NORMAL
def _stop(self):
self.interpreter.queue(Event('stop'))
self.w_btn_start['state'] = tk.NORMAL
self.w_btn_stop['state'] = tk.DISABLED
def _reset(self):
self.interpreter.queue(Event('reset'))
def _split(self):
self.interpreter.queue(Event('split'))
self.w_btn_split['state'] = tk.DISABLED
self.w_btn_unsplit['state'] = tk.NORMAL
def _unsplit(self):
self.interpreter.queue(Event('split'))
self.w_btn_split['state'] = tk.NORMAL
self.w_btn_unsplit['state'] = tk.DISABLED
def _quit(self):
self.master.destroy()