Hello! I'm just starting to program in Python and I need to create a timer. The essence of the program is that the timer starts and when the timer is running, you need to log certain events, the time of which must be saved. That is, the result should look like this:

00: 00: 24: 15 - Ivanov's comment

00: 00: 30: 24 - says Sidorov

00: 01: 12: 14 - pause

My knowledge is not enough to create such a program. Can anyone help?

  • Look in the direction of logging and {relativeCreative} format code to make notes with a time stamp relative to the start of the program. - jfs

2 answers 2

Example using qt:

 import PyQt4 def timer_action(): #Π΄Π΅Π»Π°Π΅Ρ‚, Ρ‡Ρ‚ΠΎ Π½Π°Π΄ΠΎ ΠΊΠ°ΠΆΠ΄ΡƒΡŽ сСкунду ΠΊΠ°ΠΊ ΡƒΠΆΠ΅ Π²Ρ‹ΡˆΠ΅ подсказали Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ timer = QtCore.QTimer() QtCore.QObject.connect(timer, QtCore.SIGNAL('timeout()'), timer_action) timer.start(1000) 

    Do you have a program constantly running? As an option - use time:

     import time # старт Ρ‚Π°ΠΉΠΌΠ΅Ρ€Π° begin_time = time.time() # выполняСм ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠ΅ дСйствиС time.sleep(1) # ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ врСмя окончания дСйствия с Π½Π°Ρ‡Π°Π»Π° запуска Ρ‚Π°ΠΉΠΌΠ΅Ρ€Π° end_time = time.time() print end_time - begin_time # Π΄Ρ€ΡƒΠ³ΠΎΠ΅ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠ΅ дСйствиС time.sleep(2) # ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ врСмя окончания дСйствия с Π½Π°Ρ‡Π°Π»Π° запуска Ρ‚Π°ΠΉΠΌΠ΅Ρ€Π° end_time = time.time() print end_time - begin_time 

    Displays time in seconds, in minutes and hours to translate, I hope you can)

    If difficulties arise with translation, here's an example of how to translate seconds into minutes / hours