Skip to content
Related Articles

Related Articles

Python – CellRendererText in GTK+ 3
  • Last Updated : 29 Aug, 2020

Gtk.CellRenderer widgets are used to display information within widgets such as the Gtk.TreeView or Gtk.ComboBox. Below are the seven Gtk.CellRenderer widgets used for different purposes.

  • Gtk.CellRendererText
  • Gtk.CellRendererToggle
  • Gtk.CellRendererPixbuf
  • Gtk.CellRendererCombo
  • Gtk.CellRendererProgress
  • Gtk.CellRendererSpinner
  • Gtk.CellRendererSpin
  • Gtk.CellRendererAccel

In this tutorial, we are going to discuss Gtk.CellRendererText. A Gtk.CellRendererText renders a given text in its cell, using the font, color, and style information provided by its properties. 

Text in Gtk.CellRendererText widget can be make editable by 

cell.set_property("editable", True)

Example :


from gi.repository import Gtk
import gi
gi.require_version("Gtk", "3.0")
class CellRendererTextWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title ="Geeks For Geeks")
        self.set_default_size(400, 400)
        self.liststore = Gtk.ListStore(str, str)
            ["Python Archives", ""])
            ["Python-GTK Archives", ""])
            ["Data Structures Archives", ""])
            ["Algorithms Archives", ""])
        treeview = Gtk.TreeView(model = self.liststore)
        renderer_text = Gtk.CellRendererText()
        column_text = Gtk.TreeViewColumn("Text", renderer_text, text = 0)
        renderer_editabletext = Gtk.CellRendererText()
        renderer_editabletext.set_property("editable", True)
        column_editabletext = Gtk.TreeViewColumn(
            "Editable Text", renderer_editabletext, text = 1)
        renderer_editabletext.connect("edited", self.text_edited)
    def text_edited(self, widget, path, text):
        self.liststore[path][1] = text
win = CellRendererTextWindow()
win.connect("destroy", Gtk.main_quit)

Output :

Example of CellRendererText

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :