Tkinter 3000 Clock Widget

May 9, 2001 | Fredrik Lundh

This widget shows how to use the TextMixin widget mixin for simple text-based widgets, and how to use a timer to force the widget to update at regular intervals.

from WCK import Widget, TextMixin

import time

class Clock(TextMixin, Widget):

    ui_option_height = 2
    ui_option_width = 30

    ui_doublebuffer = 1

    def __init__(self, master, **options):
        self.__time = None
        self.ui_init(master, options)
        self.__update()

    def __update(self):
        t = int(time.time())
        if t != self.__time:
            self.ui_damage() # force update
            self.__time = t
        self.after(100, self.__update)

    def ui_handle_repair(self, draw, x0, y0, x1, y1):
        self.ui_text_draw(draw)

    def ui_text_get(self):
        return time.ctime(self.__time)

To be continued…

 

A Django site. rendered by a django application. hosted by webfaction.