Glade + Python = No GUI

Discussion in 'Python' started by Kveldulv, Sep 2, 2007.

  1. Kveldulv

    Kveldulv Guest

    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
     
    Kveldulv, Sep 2, 2007
    #1
    1. Advertising

  2. Kveldulv wrote:
    > 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
     
    Wildemar Wildenburger, Sep 2, 2007
    #2
    1. Advertising

  3. Kveldulv

    Kveldulv Guest

    On Sep 2, 7:29 pm, Wildemar Wildenburger
    <> wrote:

    >
    > 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...
     
    Kveldulv, Sep 2, 2007
    #3
  4. Kveldulv wrote:
    > 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
     
    Wildemar Wildenburger, Sep 2, 2007
    #4
  5. Kveldulv

    Kveldulv Guest

    On Sep 2, 9:07 pm, Wildemar Wildenburger
    <> wrote:
    > Kveldulv wrote:
    > > 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


    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!
     
    Kveldulv, Sep 2, 2007
    #5
  6. Kveldulv

    Kveldulv Guest

    Note to myself and python noobs like me:
    Don't forget to set Visible to yes on main window in Glade :)
     
    Kveldulv, Sep 3, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hans Deragon
    Replies:
    3
    Views:
    369
    David M. Cook
    Jul 6, 2003
  2. P. Jouin

    Python and Glade-2

    P. Jouin, Jul 25, 2004, in forum: Python
    Replies:
    9
    Views:
    672
  3. Al Dykes
    Replies:
    2
    Views:
    457
    dimitri pater
    Oct 16, 2004
  4. AppelonD

    My 2nd Glade GUI with Python

    AppelonD, Jun 12, 2010, in forum: Python
    Replies:
    0
    Views:
    376
    AppelonD
    Jun 12, 2010
  5. lolveley
    Replies:
    0
    Views:
    151
    lolveley
    Apr 24, 2009
Loading...

Share This Page