Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4025506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:51:19+00:00 2026-05-20T10:51:19+00:00

I have a PyGtk treeview with a couple of columns. During runtime i add

  • 0

I have a PyGtk treeview with a couple of columns. During runtime i add constantly new rows. Each cell contains a string. Normaly, i would use a gtk.CellRenderer for each row, but I want to set the background color of each cell, according to the value inside the cell.

I tried a couple of solutions, but it seems that I have to create a CellRenderer for each cell, set the text attribute and the background color. This seems a little oversized, so i asked myself if there is a nicer solution for the problem. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:51:19+00:00Added an answer on May 20, 2026 at 10:51 am

    You can define background and foreground for your treeview cells in extra fields of the treeview data source. Then setup foreground and background attributes for the treeview columns to get their values from the corresponding data source fields.

    Below is a small example:

    import gtk
    
    test_data = [
        { 'column0' : 'test00', 'column1' : 'test01', 'f': '#000000', 'b': '#FF00FF' },
        { 'column0' : 'test10', 'column1' : 'test11', 'f': '#FF0000', 'b': '#C9C9C9' },
        { 'column0' : 'test20', 'column1' : 'test21', 'f': '#00FF00', 'b': '#FF0000' }]
    
    class TestWindow(gtk.Window):
        def __init__(self):
            gtk.Window.__init__(self)
    
            # create list storage        
            store = gtk.ListStore(str, str, str, str)
            for i in test_data:
                store.append([i['column0'], i['column1'], i['f'], i['b']])
            treeview = gtk.TreeView(store)
    
            # define columns
            column0 = gtk.TreeViewColumn("Column 0", gtk.CellRendererText(), text=1, foreground=2, background=3)        
            treeview.append_column(column0)            
            column1 = gtk.TreeViewColumn("Column 1", gtk.CellRendererText(), text=1, foreground=2, background=3)        
            treeview.append_column(column1)
    
            self.connect("destroy", lambda w: gtk.main_quit())
            self.connect("delete_event", lambda w, e: gtk.main_quit())
    
            self.add(treeview)
            self.show_all()
    
    if __name__ == "__main__":
        TestWindow()
        gtk.main() 
    

    hope this helps, regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which contains svn unified diff. My PyGTK app need to
I have a scrolled window, which contains a drawing area in pygtk. I would
I have a created a new window using pygtk. I want the system to
I have a python (pygtk) application which starts in different modes depending on arguments.
I am trying to generate a hierarchical directory listing in pyGTK. Currently, I have
I have a python program that implements pygtk for GUI. I have it running
I have seen through python - Pygtk VS Pyqt VS WxPython VS Tkinter ;
I have a project in Python 2.7 and PyGTK. I need to create a
I have a glade GUI and i'm using dome gtk.MessageDialog widgets created with pygtk
I have built PyGTK application with matplotlib graph in it. I also would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.