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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:27:36+00:00 2026-06-08T01:27:36+00:00

I am using pygtk dialog, i have added a button and i now want

  • 0

I am using pygtk dialog, i have added a button and i now want to control the positioning of the button. for example centering it.

here is my code:

import pygtk
pygtk.require('2.0')
import gtk

dlg = gtk.Dialog('Marker Label')
dlg.set_size_request(350, 300)
dlg.show()

entry = gtk.Entry()
entry.show()
entry.set_activates_default(gtk.TRUE)
dlg.vbox.pack_start(entry)

# Create a centering alignment object
align = gtk.Alignment(0.5, 0.5, 0, 0)

button = dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)

align.add(button)
dlg.vbox.pack_start(align, False, False, 5)
dlg.set_default_response(gtk.RESPONSE_OK)
response = dlg.run()

if response == gtk.RESPONSE_OK:
    label = entry.get_text()
    print label
dlg.destroy()

i am getting this message:

test.py:19: GtkWarning: Attempting to add a widget with type GtkButton to a container of type GtkAli
gnment, but the widget is already inside a container of type GtkHButtonBox, the GTK+ FAQ at http://library.gnome.org/devel/gtk-faq/stable/ explains how to reparent a widget.
align.add(button)

  • 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-08T01:27:38+00:00Added an answer on June 8, 2026 at 1:27 am

    As it says, the problem is that the button returned by dlg.add_button() already has a parent – which is the Horizontal Button Box at the bottom of the dialog.

    You could follow the FAQ – remove the button from the HButtonBox before you try to add it to your vbox. (Hint: either way, I really think you want to do all this before you set the dialog to be visible). It looks like the hbox is called “action_area”. Maybe dlg.action_area.remove(button)

    OR you could create the button yourself. Instead of using dlg.add_button(), use gtk.button_new_from_stock(gtk.STOCK_OK).

    [But I am not a Gtk programmer, and I don’t know how the event handling works in either case. I.e. I don’t know whether either of these would still close the dialog when you press the button, or whether you’d have to add something more to do that. The Gtk docs are certainly giving me that impression…]

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

Sidebar

Related Questions

As explained here , I have a simple tray icon using PyGTK. Being very
I have a created a new window using pygtk. I want the system to
I am using pygtk with glade to make a simple program which (by now)
I create a combo box using PyGTK: fileAttrCombo = gtk.ComboBox(); I want to attach
I'm creating a indicator applet using Python (pygtk) and I have a function that
I have a glade GUI and i'm using dome gtk.MessageDialog widgets created with pygtk
I want to have a dialog window where some buttons close the dialog and
I'm working on a project using Python and pyGTK. I have a window whose
Using the Generator class from http://unpythonic.blogspot.com/2007/08/using-threads-in-pygtk.html , the following code makes my program fail:
I am using this example http://www.pygtk.org/pygtk2tutorial/examples/testtext.py but it doesn't work i see only white

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.