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 :

Python3




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)
        self.liststore.append(
            ["Python Archives", "https://www.geeksforgeeks.org/category/programming-language/python/"])
        self.liststore.append(
            ["Python-GTK Archives", "https://www.geeksforgeeks.org/tag/python-gtk/"])
        self.liststore.append(
            ["Data Structures Archives", "https://www.geeksforgeeks.org/category/data-structures/"])
        self.liststore.append(
            ["Algorithms Archives", "https://www.geeksforgeeks.org/category/algorithm/"])
  
        treeview = Gtk.TreeView(model = self.liststore)
  
        renderer_text = Gtk.CellRendererText()
        column_text = Gtk.TreeViewColumn("Text", renderer_text, text = 0)
        treeview.append_column(column_text)
  
        renderer_editabletext = Gtk.CellRendererText()
        renderer_editabletext.set_property("editable", True)
  
        column_editabletext = Gtk.TreeViewColumn(
            "Editable Text", renderer_editabletext, text = 1)
  
        treeview.append_column(column_editabletext)
  
        renderer_editabletext.connect("edited", self.text_edited)
  
        self.add(treeview)
  
    def text_edited(self, widget, path, text):
        self.liststore[path][1] = text
  
  
win = CellRendererTextWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

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.




My Personal Notes arrow_drop_up
Recommended Articles
Page :