Forums

python3 + gtk3 color sequence

Hello guys, I have a "little" problem, I tried to run a little program, it's very simple, when click a button the background of the label fill with the red color and after one second fill with green color, I wrote this code but only fill the label with green color

#!/usr/bin/python3
import os
import time
import gi
from gi.repository import Gtk, Gdk, Pango, Vte, GLib, GdkPixbuf


class GridWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="NEOTECH")
self.grid = Gtk.Grid()
self.add(self.grid)

self.btnStartTest=Gtk.Button("Iniciar Prueba")
self.btnStartTest.connect("clicked",self.StartTest)
self.label1 = Gtk.Label("NUMERO DE SERIE")
self.grid.add(self.btnStartTest)
self.grid.attach(self.label1,0,1,1,1)


def StartTest(self,widget):
color = Gdk.color_parse('red')
rgba = Gdk.RGBA.from_color(color)
self.label1.override_background_color(0,rgba)
time.sleep(3)
color = Gdk.color_parse('green')
rgba = Gdk.RGBA.from_color(color)
self.label1.override_background_color(0,rgba)
print("fin")


win = GridWindow()
win.set_position(Gtk.WindowPosition.CENTER)
win.set_default_size(1000,480)
win.set_type_hint(Gdk.WindowTypeHint.MENU)
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

any idea what is wrong in my code?

[edited by admin: formatting]

Are you running this on PythonAnywhere?

no, I am running this code in my PC.