views:

254

answers:

2

I am just starting to learn Glade with pyGTK. Since Glade makes XML files instead of actual python code, is there a good way to start a project with Glade and then hand code more or tweak it?

Are there times or reasons it would be preferrable to hand code all of it instead of starting with glade?

+2  A: 

How much do you know about glade and pygtk? Glade creates xml files but you load these using gtk.Builder in python. You can easily tweak any widgets you created with glade in python. Read these tutorials to understand how to do it better. You just need to learn more about pygtk and glade and it will be obvious.

DoR
I know very little so far, I started playing with them two days ago. I have started going through the tutorials and I have used glad to make a couple of simple guis, but so for it has just been putting guis around formerly command line programs so they are hardly sophisticated.Thanks for the link.
TimothyAWiseman
+1  A: 

GUI's created with glade are accessible in the code in two way: libglade or gtkbuilder. I cannot comment much on the differences between the two, other than that gtkbuilder is newer; there are a lot of pages on google that show how to migrate from libglade to gtkbuilder.

Using gtkbuilder, you can create your GUI object by retrieving it from the the XML file using gtkbuilder. This creates the object with all of the settings you set in glade. You now have an GUI object which you can manipulate via it's regular interface.

builder = gtk.Builder()
builder.add_from_file(glade_path)
builder.connect_signals(self)

main_window = builder.get_object("main_window")
main_window.show()

text_box1 = builder.get_object("textbox1")
text_box1.set_text("enter your name")

Line 3 shows how signal handlers are attached when loaded from glade. Essentially, it looks for the function you specified for the signal in the glade interface and attached to it; if the function isn't provided, you'll see a warning on the command line.

rioch
Thank you. That is quite helpful.
TimothyAWiseman