Glade + Python = No GUI

K

Kveldulv

I made simple GUI in Glade 3 (Ubuntu 7.04) consisting of only 2
buttons. When I run
2buttonsgui.py, no GUI pops out

#!/usr/bin/env python
import pygtk
import gtk.glade

class TwoButtonsGUI:
def __init__(self):
self.window = gtk.glade.XML("/home/myusername/Desktop/
2buttons.glade", "window1")

if __name__ == '__main__':
TwoButtonsGUI()
gtk.main()

When interrupted, I get

File "gui.py", line 11, in <module>
gtk.main()

When GUI coded manually, all works.

Thanks in advance
 
W

Wildemar Wildenburger

Kveldulv said:
I made simple GUI in Glade 3 (Ubuntu 7.04) consisting of only 2
buttons. When I run
2buttonsgui.py, no GUI pops out

#!/usr/bin/env python
import pygtk
import gtk.glade

class TwoButtonsGUI:
def __init__(self):
self.window = gtk.glade.XML("/home/myusername/Desktop/
2buttons.glade", "window1")

if __name__ == '__main__':
TwoButtonsGUI()
gtk.main()

When interrupted, I get

File "gui.py", line 11, in <module>
gtk.main()

When GUI coded manually, all works.
Shouldnt there be more to that error message of yours? I would expect
something like "NameError: name 'gtk' is not defined"?

Because as it seems you haven't impored gtk (only gtk.glade). So adding
"import gtk" at the beginning should help.

I may be wrong; I recall some weird importing requirements for pygtk, so
I'm not sure if I'm to uninformed to see the actual problem.

/W
 
K

Kveldulv

Shouldnt there be more to that error message of yours? I would expect
something like "NameError: name 'gtk' is not defined"?

Because as it seems you haven't impored gtk (only gtk.glade). So adding
"import gtk" at the beginning should help.

I may be wrong; I recall some weird importing requirements for pygtk, so
I'm not sure if I'm to uninformed to see the actual problem.

/W


Nope, everything imports well, no errors. With import gtk added,
I get the same thing...
 
W

Wildemar Wildenburger

Kveldulv said:
When interrupted, I get

File "gui.py", line 11, in <module>
gtk.main()
Ah, I see now. Thats just telling you that *you* interrupted the
function/method/whateverthatis.
When GUI coded manually, all works.
Hence: Something in your (generated) code or XML file is corrupt or
missing. Perhaps some sort of show() call or attribute. I really only
have marginal experience with pygtk so I'm just stabbing at thin air.

sorry :(
/W
 
K

Kveldulv

Ah, I see now. Thats just telling you that *you* interrupted the
function/method/whateverthatis.


Hence: Something in your (generated) code or XML file is corrupt or
missing. Perhaps some sort of show() call or attribute. I really only
have marginal experience with pygtk so I'm just stabbing at thin air.

sorry :(
/W

I sorted it out and you're right. I didn't found out why this thing
didn't work since
it's c/pasted straight from the book I'm learning from but this did
the trick:

class TwoButtonsGUI:
def __init__(self):
xml = gtk.glade.XML("buttons.glade")


self.window = xml.get_widget("window1")
self.window.show()

etc

Thanks for help!
 
K

Kveldulv

Note to myself and python noobs like me:
Don't forget to set Visible to yes on main window in Glade :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top