PyGTK: Digital Clock

Linux tutorials and code.
1 post Page 1 of 1
Contributors
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

PyGTK: Digital Clock
mikethedj4
Source - http://stackoverflow.com/questions/6892 ... gtk-window

I added some additional options so you can change the color if you like.
Code: Select all
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import pango
import time

class Clock:

  def __init__(self):
	me = gtk.Window(gtk.WINDOW_TOPLEVEL)
	me.connect("destroy", lambda w: gtk.main_quit())
	me.set_resizable(False)
	me.set_property('skip-taskbar-hint', True)
	self.label = gtk.Label()
	self.label.modify_font(pango.FontDescription("FreeSerif Bold 50"))
	attr = pango.AttrList()
	fg_color = pango.AttrForeground(65535, 0, 0, 0, 65535)
	attr.insert(fg_color)
	self.label.set_attributes(attr)
	
	me.add(self.label)
	me.show_all()

  def update(self):
	self.label.set_text(time.strftime('%H:%M:%S'))
	return True  # needed to keep the update method in the schedule

clock = Clock()
gtk.timeout_add(200, clock.update)  # add to the main loop scheduled tasks
gtk.main()
1 post Page 1 of 1
Return to “Programming”