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 7904537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:07:14+00:00 2026-06-03T10:07:14+00:00

I’m trying to apply a combobox to a small GTK3 interface, but I can’t

  • 0

I’m trying to apply a combobox to a small GTK3 interface, but I can’t really figure out how to populate its list, and how to connect the interface’s combobox with my python code.

Could someone show me how in a little example? The rest of it I will be able to finish.

  • 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-06-03T10:07:20+00:00Added an answer on June 3, 2026 at 10:07 am

    ComboBoxes, like TextViews or TreeViews are widgets that clearly separates the View (what it looks like) from the Model (What info they hold). You need to do in Glade:

    1. Add a Combobox to some place in the GUI.
    2. Create a ListStore that will hold the data. Configure the Liststore to whatever columns you need to have (each column has a type).
    3. Return to the combobox, set the previous created Liststore as it’s model.
    4. Edit the combobox (right click, edit) and add a cell renderer. Map that cell renderer to display data from some column of the model.
    5. If your data is static, within Glade you can add rows to your ListStore. If your data is dynamic you will need to get the liststore in your code and then fill it with list that have the same type of elements as your liststore.

    The smaller example I could think of is this one:

    test.glade

    <?xml version="1.0" encoding="UTF-8"?>
    <interface>
      <!-- interface-requires gtk+ 3.0 -->
      <object class="GtkListStore" id="myliststore">
        <columns>
          <!-- column-name code -->
          <column type="gchararray"/>
          <!-- column-name legible -->
          <column type="gchararray"/>
        </columns>
      </object>
      <object class="GtkWindow" id="window">
        <property name="can_focus">False</property>
        <property name="window_position">center-always</property>
        <property name="default_width">400</property>
        <signal name="destroy" handler="main_quit" swapped="no"/>
        <child>
          <object class="GtkBox" id="box">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkLabel" id="label">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">Best color in the world:</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkComboBox" id="mycombobox">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="model">myliststore</property>
                <signal name="changed" handler="combobox_changed" swapped="no"/>
                <child>
                  <object class="GtkCellRendererText" id="renderer"/>
                  <attributes>
                    <attribute name="text">1</attribute>
                  </attributes>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
    </interface>
    

    test.py

    from gi.repository import Gtk
    from os.path import abspath, dirname, join
    
    WHERE_AM_I = abspath(dirname(__file__))
    
    class MyApp(object):
    
        def __init__(self):
            # Build GUI
            self.builder = Gtk.Builder()
            self.glade_file = join(WHERE_AM_I, 'test.glade')
            self.builder.add_from_file(self.glade_file)
    
            # Get objects
            go = self.builder.get_object
            self.window = go('window')
            self.myliststore = go('myliststore')
            self.mycombobox = go('mycombobox')
    
            # Initialize interface
            colors = [
                ['#8C1700', 'Redish'],
                ['#008C24', 'Greenish'],
                ['#6B6BEE', 'Blueish'],
    
            ]
            for c in colors:
                self.myliststore.append(c)
            self.mycombobox.set_active(0)
    
            # Connect signals
            self.builder.connect_signals(self)
    
            # Everything is ready
            self.window.show()
    
        def main_quit(self, widget):
            Gtk.main_quit()
    
        def combobox_changed(self, widget, data=None):
            model = widget.get_model()
            active = widget.get_active()
            if active >= 0:
                code = model[active][0]
                print('The code of the selected color is {}'.format(code))
            else:
                print('No color selected')
    
    if __name__ == '__main__':
        try:
            gui = MyApp()
            Gtk.main()
        except KeyboardInterrupt:
            pass
    

    Kind regards

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.