[Tutor] How to extract variables from GUI objects

Eric Kelly ericdavidkelly at gmail.com
Wed Aug 19 01:08:00 CEST 2015

I am a beginner with Python and would like to write a program that includes
a GUI to run it.  I've been through a tutorial on using Python but I'm
trying to also use Gtk and Glade to make the GUI.  I've tried to use the
docs and other tutorials but alas I'm still stuck.

The problem is simply to get the text from a combotext object.  I
simplified the program by only including the combo object and a "Run"
button.  The user should be able to choose a value from the list or enter a
different value manually.  When I click the "Run" button to print the combo
text, I think I get the memory address.  Here is the message that appears
when I click Run:

"<ComboBoxText object at 0x26a9d78 (GtkComboBoxText at 0x41ae178)>"

I realize that the program does not know what part of the object to get,
but I am unclear about how to tell it where the text is.  I've tried
assigning variable names to what I think are the appropriate user data
values, but of course none worked.  I'm using Glade 3, Gtk+ 3, and Python

Thanks in advance for any help and suggestions (I'm sure there are other
mistakes here too).


The Python code is here:
from gi.repository import Gtk

# Make a window to control the program
class MyGI(Gtk.Window):

    def __init__(self):
        self.builder = Gtk.Builder()

        # Define handlers for signals from window
        handlersDict = {

        # Get the objects from the window
        self.window = self.builder.get_object('applicationwindow1')
        self.buttonRun = self.builder.get_object('buttonRun')

        # Connect the signals with their handlers

    def on_buttonRun_clicked(self,widget):
        comboText = self.builder.get_object('comboboxtext1')

def main():
    win = MyGI()

if __name__ == '__main__':

The XML code is here:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkApplicationWindow" id="applicationwindow1">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <signal name="destroy" handler="on_applicationwindow1_destroy"
      <object class="GtkBox" id="box1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
          <object class="GtkComboBoxText" id="comboboxtext1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="margin_bottom">5</property>
              <item translatable="yes">0</item>
              <item translatable="yes">100</item>
              <item translatable="yes">200</item>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          <object class="GtkButton" id="buttonRun">
            <property name="label" translatable="yes">Run</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_buttonRun_clicked"
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>

More information about the Tutor mailing list