Creating a ticking watch without referencing to the systemclock

First of all, I wish everyone a happy new year.

Secondly, I tried to build my own clock without referencing to the system clock.

I can write the program in several ways, but it don´t won´t work.

Do you have an clue?

Thanks, BR Bashi

import time
from tkinter import *
# Objekt der Klasse Tk erstellt und Fensterüberschrift
fenster = Tk()          
# Uhrzeit wird über ein Label angezeigt und mit pack im fenster gezeigt
uhr = Label(master=fenster,
            width = 15,
            height = 3)
zeit = ''
# Abfrage der Zeit vom laufenden Computer
# mit config wird das Label neu beschriftet
# mit after wird nach 0,2sek die Funktion tick neu aufgerufen
def tick(hour,min):
    global zeit
    if len(str(hour))<2:
    if len(str(min))<2:
    neuezeit = f"{hour}:{min}"
    if neuezeit != zeit:
        zeit = neuezeit
        uhr.config(text = zeit)

def tick23(x,y):
    if int(x)<24:
        if int(y)==59:
    if len(str(x))<2:
    if len(str(y))<2:
    return f"{x}:{y}"     
uhr.mainloop() # Programm startet

I don’t understand why this is useful.

The program can only work if it has some idea of how much time has passed.

It can say to wait for a certain amount of time (e.g. with time.sleep), but it does this by asking the system to pause it. And then, it doesn’t know if the pause was exact, and it also doesn’t know how much time it has spent on its own calculation.

So checking the system clock is the only thing that makes sense, in order to know the current time. That’s why there is a system clock.

But, I don´t want use the system clock.

Because, if there is no possibility to write this program in python, how will work the system clock.

Conclusion: When the system clock has a program, we can reproduce it in python.


Not really. Every clock application you see on your system is referencing the same ticking clock. In the pre-internet-everywhere era, when most home computers had to operate entirely on their own, it was vital to have a clock that kept good time even with the computer powered off, without any sort of external reference; and even today, that feature is serving us well, with only minor adjustments needed (NTP is usually just going to slightly tweak the clock to bring it in sync, rather than making visual changes).

So for that to work, you need something that ISN’T a program. You need a dedicated timer chip, one that requires very little power (so it can run off batteries in a powered-off computer), but still is pretty accurate. Ultimately, one way or another, that’s going to maintain some sort of ever-increasing clock value on the motherboard, which the operating system can both query and update, and which then takes care of the actual ticking work.

Your “after” method call here is hiding a call to an OS-provided time-of-day query, as will any kind of “sleep for one second” call, or anything of that nature. It always will, because it’s the only way to be reliable.

The system clock isn’t actually a program, it’s probably an off-the-shelf chip with a little sliver of quartz in it as an oscillator. If done right, all the computer actually has to do is count - which electronic circuits are pretty good at doing!

But how works the timerchip? On the timerchip must be also a program, or?

I know the easy way is to use the os clock, but I would like to reproduce this timerchip.

For the first, it´s for me enough, that this works, when the program starts.
And the second step (far away in the future), to run the program in the background and reference all apps to this time.
Thanks, BR Bash

Modern systems are inevitably more complicated than this, but ultimately, the way a timer chip will most likely work is with some sort of crystal oscillator. Here’s a great explanation from Steve Mould on the subject:

You can’t reproduce that in software. It’s not just running code; it’s making use of the physical and electromagnetic properties of the quartz.

Ok - But the bios or DOS from a PC must somehow communicate with this timerchip?

Yes. Back when I was programming in assembly language, you could use I/O ports to control it, and it would send CPU interrupts at regular intervals. Obviously you won’t be writing code like that from userspace, but that’s what your OS is doing under the hood somewhere.

Ok - Do you have any additional information about this?