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

  • Home
  • SEARCH
  • 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 8103783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:39:02+00:00 2026-06-05T23:39:02+00:00

I’m trying to learn GUI programming using python2 and GTKBuilder, but I get a

  • 0

I’m trying to learn GUI programming using python2 and GTKBuilder, but I get a segmentation fault when I run the code. This is my file, created in Glade as a GTKBuilder file:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.0 -->
  <object class="GtkWindow" id="mainWindow">
    <property name="can_focus">False</property>
    <child>
      <object class="GtkBox" id="box1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkBox" id="box2">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="halign">start</property>
            <property name="margin_left">146</property>
            <property name="margin_right">276</property>
            <child>
              <object class="GtkLabel" id="label1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">label</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkEntry" id="entryName">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="margin_bottom">4</property>
                <property name="hexpand">True</property>
                <property name="vexpand">True</property>
                <property name="invisible_char">●</property>
                <property name="placeholder_text">Please enter your name here...</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="buttonWriteNameToFile">
            <property name="label" translatable="yes">button</property>
            <property name="use_action_appearance">False</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="use_action_appearance">False</property>
            <signal name="clicked" handler="buttonWriteNameToFile_clicked" swapped="no"/>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>

My python code, based on this question, is this:

#!/usr/bin/env python

import gtk

class NameApp:
    def __init__(self):
        filename = "project.glade"
        builder = gtk.Builder()
        builder.add_from_file(filename)
        builder.connect_signals(self)
        builder.get_object("mainWindow").show_all() 

    def buttonWriteNameToFile_clicked(self, widget):
        print("File write code...")

if __name__ == "__main__":
    app = NameApp()
    gtk.main()

Running the file with python2 yields this error:

name.py:9: Warning: cannot create instance of abstract (non-instantiatable) type `GtkBox'
  builder.add_from_file(filename)
./geany_run_script.sh: line 5: 14897 Segmentation fault      python2 "name.py"

I thought I followed that example as closely as possible, and I don’t see any differences outside of the GTKBuilder file. However, the example in the linked question runs successfully on my machine. I don’t know if it’s relevant, but I’m running Arch Linux x86_64.

  • 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-05T23:39:05+00:00Added an answer on June 5, 2026 at 11:39 pm

    If you prefer 3.x version (as it can be read in your Glade file) you have to use GTK from GObject Introspection module. The modified code of yours is the following.

    #!/usr/bin/env python
    
    #import gtk
    from gi.repository import Gtk 
    
    class NameApp:
        def __init__(self):
            filename = "test.glade"
            builder = Gtk.Builder()
            builder.add_from_file(filename)
            builder.connect_signals(self)
            builder.get_object("mainWindow").show_all() 
    
        def buttonWriteNameToFile_clicked(self, widget):
            print("File write code...")
    
    if __name__ == "__main__":
        app = NameApp()
        Gtk.main()
    

    In the 2.x versions of GTK the widget GtkBox was abstract, so you cannot instantiate it. You can use GtkHBox or GtkVBox.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
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
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.