3
I am trying to create a clock in Pygtk. But it seems that there was some semantic error here:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import pygtk
pygtk.require('2.0')
import gtk
from datetime import *
def relogio():
janela = gtk.Window()
janela.set_title("Relógio digital")
label = gtk.Label()
janela.add(label)
janela.connect("destroy", gtk.main_quit)
janela.show_all()
while 1:
label.set_markup("<big>" + str(datetime.now().hour) + ":" + str(datetime.now().minute) + ":" + str(datetime.now().second) + "</big>")
if __name__ == '__main__':
relogio()
gtk.mainloop()
Could you help me fix it? Notice that when you run the code with the interpreter, the window just doesn’t appear!
It would be the case to change the clock update to another function called by a timer. As it is, the infinite loop does not allow the return of the clock() function, never reaching the gtk.mainloop(), which would anyway disturb the refresh of the screen even if it appeared. Also, with an infinite loop of these without any gap or anything, your watch will be a beautiful CPU consumer...
– Bacco
Right... what do I do to fix, then?
– Gabriel
Good morning, always use titles referring to the problem, "What’s wrong", "Help", "Help", "Please" do not define anything and do not help at all to understand the problem, are redundant, since when someone posts a doubt here is that probably the code is not even working as expected. Take this comment as a constructive criticism.
– Guilherme Nascimento