Ahh, sehr gut, so gehts (Frisur gerettet

Vielen Dank!
Gruß, mawe
Code: Alles auswählen
def click(self,event):
print self.label
self.set_bg_color("white")
Code: Alles auswählen
import pygtk
pygtk.require('2.0')
import gtk
class ColoredButton(gtk.Button):
def __init__(self, label=None, stock=None, use_underline=True,
states=(gtk.STATE_NORMAL, gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE)):
super(ColoredButton, self).__init__(label, stock, use_underline)
self.states = states
self.label = label
self.cm = self.get_colormap()
self.connect("clicked", self.click)
def click(self,event):
print self.label
self.set_bg_color("white")
def set_bg_color(self, bg):
rc_style = gtk.RcStyle()
bgc = self.cm.alloc_color(bg)
self.set_style(None)
self.modify_style(rc_style)
for state in self.states:
self.modify_bg(state, bgc)
self.child.set_use_markup(True)
elements = ["H","C"]
root = gtk.Window(gtk.WINDOW_TOPLEVEL)
root.connect("destroy", lambda w: gtk.main_quit())
table = gtk.Table(1,2)
root.add(table)
c,r = 0,0
for atom in elements:
button = ColoredButton(label=atom)
if atom == "H":
button.set_bg_color("red")
else:
button.set_bg_color("blue")
table.attach(button,c,c+1,r,r+1)
button.show()
c+=1
table.show()
root.show()
gtk.main()