Glade + Python = No GUI

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kveldulv

    Glade + Python = No GUI

    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

  • Wildemar Wildenburger

    #2
    Re: Glade + Python = No GUI

    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

    Comment

    • Kveldulv

      #3
      Re: Glade + Python = No GUI

      On Sep 2, 7:29 pm, Wildemar Wildenburger
      <lasses_w...@kl apptsowieso.net 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...

      Comment

      • Wildemar Wildenburger

        #4
        Re: Glade + Python = No GUI

        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

        Comment

        • Kveldulv

          #5
          Re: Glade + Python = No GUI

          On Sep 2, 9:07 pm, Wildemar Wildenburger
          <lasses_w...@kl apptsowieso.net 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.sho w()

          etc

          Thanks for help!

          Comment

          • Kveldulv

            #6
            Re: Glade + Python = No GUI

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



            Comment

            Working...