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 menu font size -method to change tonycat 2 1,993 Oct-11-2020, 02:43 AM
Last Post: tonycat
  tkinter | Button color text on Click Maryan 2 877 Oct-09-2020, 08:56 PM
Last Post: Maryan
  Tkinter - How can I change the default Notebook border color? TurboC 4 4,255 Oct-06-2020, 10:35 PM
Last Post: TurboC
  [Tkinter] Trying to change font size w/o changing button size python63 3 4,695 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  [tkinter] color change for hovering over button teacher 4 3,148 Jul-04-2020, 06:33 AM
Last Post: teacher
  [PyQt] Increase text size and change color based on temp pav1983 5 862 Jun-22-2020, 10:52 PM
Last Post: menator01
  TKINTER - Change font color for night or day Ayckinn 2 1,427 May-24-2020, 09:25 PM
Last Post: Ayckinn
  [Tkinter] changing background color of a button ieee488 2 2,205 Sep-06-2019, 01:24 PM
Last Post: ieee488
  change background color of button ieee488 3 6,636 Jul-30-2019, 09:49 PM
Last Post: ieee488
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 2,222 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

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