@bober1131
Python, HTML, CSS, c#, c++.

Как сделать времяы нажатия между кнопками старт и стоп?

class IncrediblyCrudeClock(Label):
def update(self, *args):
self.text = time.asctime()
def start(self):
Clock.schedule_interval(self.tick,1)

timepassed = 0

def countsecond(dt):
global timepassed
timepassed += 1


layout = BoxLayout(padding = 100, orientation='vertical')
button_start = Button(text = "start")
button_stop = Button(text = "stop")
crudeclock = IncrediblyCrudeClock()
Clock.schedule_interval(crudeclock.update, 1)
label = Label(text = str(timepassed))
event = Clock.schedule_interval(countsecond, 1)
Clock.unschedule(event)
currentline = BoxLayout()

def showtime(instance):
global currentline
currentline = BoxLayout()
timestart = IncrediblyCrudeClock()
Clock.schedule_once(timestart.update)
currentline.add_widget(timestart)
timepassed = 0
event()
layout.remove_widget(instance)
layout.add_widget(button_stop)
layout.add_widget(currentline)

def hidetime(instance):
Clock.unschedule(event)
global label
label = Label(text = str(timepassed))
global currentline
timestop = IncrediblyCrudeClock()
Clock.schedule_once(timestop.update)
currentline.add_widget(timestop)
currentline.add_widget(label)
line = currentline
layout.remove_widget(currentline)
layout.remove_widget(instance)
layout.add_widget(button_start)
layout.add_widget(line)


class TimeApp(App):
def build(self):
layout.add_widget(button_start)
crudeclock = IncrediblyCrudeClock()
Clock.schedule_interval(crudeclock.update, 1)
button_start.bind(on_press = showtime)
button_stop.bind(on_press = hidetime)
return layout
  • Вопрос задан
  • 100 просмотров
Пригласить эксперта
Ответы на вопрос 1
RusiDev
@RusiDev
time.time()
Return the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.

На кнопке старт делаете: start_time = time.time()
На кнопке финиш ставите: end_time = time.time()
А затем на финише вычитаете конечное время минус время старта:
end_time - start_time
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы