Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-04-2013, 07:35 AM   #1
LQ Newbie
Registered: Aug 2003
Location: Atlanta, GA
Distribution: Linux Mint 14
Posts: 15

Rep: Reputation: 0
Unhappy GTK+ / Python spawn child window button press

I have been searching the web for 4 days now and I am unable to find an answer to my question. I've scoured the gnome website, but their GTK 3 documentation needs work. To me, it looks like a wall of text and is more of a command reference than actual useful documentation for someone who is learning. Anyways, end of rant.

I'm trying to write a simple program using GTK and Python. It should open a main window with a button. When the button, it should spawn a child window with a label. I cannot for the life of me get it to work. Could someone please help me figure out what I'm doing wrong??

from gi.repository import Gtk

class MainWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Main Window")
        test_button = Gtk.Button(label="Click Here")
        test_button.connect("clicked", self.on_button_click)
        grid = Gtk.Grid()
        grid.attach(test_button, 1, 1, 1, 1)
    def on_button_click(self, widget):
class ButtonWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Child Window")
        child_win.connect("destroy", self.destroy)
        grid = Gtk.Grid()
        test_label = Gtk.Label(label="Label on child window")
        grid.attach(test_label, 1, 1, 1, 1)

main_win = MainWindow()
child_win = ButtonWindow()
main_win.connect("delete-event", Gtk.main_quit)
This code does not work. The main window spawns with a button, but clicking it does not spawn the child window. I have seen some programs that spawn a child window, but all of them close it with Gtk.main_quit, which then closes the entire program. Is GTK meant to only have 1 main window with no external windows?
Old 03-05-2013, 07:21 AM   #2
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

Rep: Reputation: 32
You have created the window object but you need to call show_all on the new window for it to appear as the first time you called it the window has not been created yet. If it had and was a child of MainWindow then it would show as well


child, gtk+, gtk3, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python GTK click and toggle button? nutjob16 Programming 1 11-29-2012 02:08 AM
[SOLVED] ubuntu 9.10 defaults to black screen and prompt. no gtk window. python prob? drogue Ubuntu 1 11-30-2009 05:08 PM
Python, Glade, using number keys to press button donnied Programming 0 01-20-2008 06:58 PM
Cannot allocate memory: couldn't spawn child joshfields Linux - General 2 01-14-2006 10:39 PM
python/glade attach window content in gtk.fixed() a10392 Linux - Software 3 10-08-2004 09:19 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration