Python Forum
PyGTK3, I can't Change Button and Table Backgorund Color using modify_bg method.
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyGTK3, I can't Change Button and Table Backgorund Color using modify_bg method.
#1
hello, i can't change button and table bakckground color using modify_bg method i don't know how can i change. 


my code...

import gi
gi.require_version("Gtk", "3.0")
from gi.repositroy import Gtk as gtk, Gdk as gdk

btn1 = gtk.Button("example")
btn1.modify_bg(gtk.StateType.NORMAL, gdk.color_parse("red") ) #not working 
Reply
#2
Very first link: http://bfy.tw/ArYh
http://stackoverflow.com/a/1241609

import gtk

win = gtk.Window()
win.connect("destroy", gtk.main_quit)

btn = gtk.Button("test")

#make a gdk.color for red
map = btn.get_colormap() 
color = map.alloc_color("red")

#copy the current style and replace the background
style = btn.get_style().copy()
style.bg[gtk.STATE_NORMAL] = color

#set the button's style to the one you created
btn.set_style(style)

win.add(btn)
win.show_all()

gtk.main()
Reply
#3
@nilamo

But i use pygtk3, i hope, that works on pygtk3. Thanks. I m gonna try

Edit:
I tried. code didn't work and gave error: " 'Button' object has no attribute 'get_colormap' "

topic is still up to date

topic is still up to date
Reply
#4
#!/usr/bin/python3
import os
import time
import gi
from gi.repository import Gtk, Gdk

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('green')
        rgba = Gdk.RGBA.from_color(color)
        self.label1.override_background_color(0,rgba)
   

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] how to make label or button not visible with the place method? nowayj63 2 2,636 Jan-03-2023, 06:29 PM
Last Post: Yoriz
  Can't change the colour of Tk button text Pilover 6 14,496 Nov-15-2022, 10:11 PM
Last Post: woooee
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 4,761 Aug-23-2022, 09:11 PM
Last Post: Extra
  [WxPython] [SOLVED] How to change button label? Winfried 3 2,020 May-31-2022, 06:37 PM
Last Post: Winfried
  Tkinter - How can I change the default Notebook border color? TurboC 5 14,629 May-23-2022, 03:44 PM
Last Post: bigmac
Question [Tkinter] Change Treeview column color? water 3 9,412 Mar-04-2022, 11:20 AM
Last Post: Larz60+
  Can't get tkinter button to change color based on changes in data dford 4 3,362 Feb-13-2022, 01:57 PM
Last Post: dford
  Tkinter menu font size -method to change tonycat 2 7,700 Oct-11-2020, 02:43 AM
Last Post: tonycat
  tkinter | Button color text on Click Maryan 2 3,314 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [Tkinter] Trying to change font size w/o changing button size python63 3 9,730 Aug-05-2020, 01:04 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020