Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am using Quickly and Glade for the first time. I want to add certain widgets such as label and buttons on viewport via python code. Is it possible?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Yes, you can. If you haven't already loaded the glade file the load it with:

builder = gtk.Builder()
builder.add_from_file("/path/to/file")

Replace "/path/to/file" with the path to the glade file. You can then get the container like the viewport:

viewport = builder.get_object("nameOfViewport")

Replace "nameOfViewport" with what you named it in glade. You can then add the widget using the view ports add() method:

viewport.add(nameOfWidget)

Replace "nameOfWidget" with the name of the widget you want to add.

Edit: Make sure you initialize the widget with something like

nameOfWidget = gtk.Label()

for a label widget.

share|improve this answer
    
Hii i tried with it, giving error as, TypeError: Expected Gtk.Widget, but got GObjectMeta –  gau1991 Jun 21 '12 at 15:43
1  
When adding the widget you need to either initialize it using something like "label = gtk.Label()" and then add label to the viewport or just "viewport.add(gtk.Label())" but I would reccomend the first method. –  Sam Bickley Jun 21 '12 at 15:54
    
Thanks buddy now its working... –  gau1991 Jun 21 '12 at 16:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.