Advertisement
metalx1000

Python GTK Clock

Sep 1st, 2017
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8  -*-
  3.  
  4. import pygtk
  5. pygtk.require('2.0')
  6. import gtk
  7. import time
  8.  
  9. class Clock:
  10.  
  11.     def __init__(self):
  12.         window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  13.         window.connect("destroy", lambda w: gtk.main_quit())
  14.         window.set_title("Clock")
  15.         self.label = gtk.Label()
  16.         window.add(self.label)
  17.         window.set_border_width(25)
  18.         window.show_all ()
  19.  
  20.     def update(self):
  21.         self.label.set_text(time.strftime('%H:%M:%S'))
  22.         return True  #needed to keep the update method in the schedule
  23.  
  24. def main():
  25.     gtk.main()
  26.  
  27. if __name__ == "__main__":
  28.     clock = Clock()
  29.     gtk.timeout_add(200, clock.update)  #add to the main loop scheduled tasks
  30.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement