wxPython beginners problem

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

    wxPython beginners problem

    Hello all,

    I'm new to python, new as newbies get, so please, don't take wrongly
    if this seems like a stupid or overly simple question.

    I'm going through examples in a book I have ("Beginning python", by
    Hetland Marcus) and I just started doing wxPython examples.

    But every sample I try, for example:

    import wx
    app = wx.App()
    win = wx.Frame(None, title="Simple editor")
    loadButton = wx.Button(win, label='Open')
    saveButton = wx.Button(win, label='Save')
    win.Show
    app.MainLoop()

    closes too fast. After running in python IDLE just the line
    === restart ===
    shows up.

    How can I keep the window to "stay alive" so I see what I get ?
    I'm on a winxp platform using python 2.5.2. if that matters.

    Please, any help, constructive advice and ideas are very much
    appreciated.

    Best regards
    Ivan Reborin
  • Ivan Reborin

    #2
    Re: wxPython beginners problem

    On Fri, 15 Aug 2008 18:31:16 +0200, Ivan Reborin <ireborin@gmail .com>
    wrote:
    >Hello all,
    >
    >I'm new to python, new as newbies get, so please, don't take wrongly
    >if this seems like a stupid or overly simple question.
    >
    >I'm going through examples in a book I have ("Beginning python", by
    >Hetland Marcus) and I just started doing wxPython examples.
    >
    >But every sample I try, for example:
    >
    >import wx
    >app = wx.App()
    >win = wx.Frame(None, title="Simple editor")
    >loadButton = wx.Button(win, label='Open')
    >saveButton = wx.Button(win, label='Save')
    >win.Show
    >app.MainLoop ()
    >
    >closes too fast. After running in python IDLE just the line
    >=== restart ===
    >shows up.
    >
    >How can I keep the window to "stay alive" so I see what I get ?
    >I'm on a winxp platform using python 2.5.2. if that matters.
    >
    >Please, any help, constructive advice and ideas are very much
    >appreciated.
    >
    >Best regards
    >Ivan Reborin
    I would just add that actually the process doesn't finish at all. When
    I look at the task manager, the process pythonw.exe stays there (about
    22mb memory).

    Tkinter examples work on the other hand.

    And, just another question, if I may while I'm here. The reason that
    I'm learning python (apart from finishing my degree :) is that I'm
    trying to create a gui for my fortran subroutines:
    - back calculating in fortran, very time consuming processes (about
    15min per calculation on 2ghz dual core cpu, and I have a lot of
    those) so I'm not even thinking of doing it in any other languages,
    and a gui in python which will have to draw some x-y diagrams as a
    result of the calculation
    I choose python because I like the syntax and 'its way of thinking',
    and because I've heard it has a good reputation of 'getting along'
    with other languages.

    Has anyone done something like this ? Is there any differences,
    advantages and disadvantages against one or the other gui-s currently
    available (i like wxpython and tkinter for now, as I've heard a lot of
    good comments about them) ?

    I would appreciate your opinion, if you can spare the time. All
    comments would be greatly appreciated.

    Best regards
    Ivan Reborin

    p.s. Sorry if my english is not so good. It's not my main language,
    actually, not even my secondary language :-( but I'm trying to improve
    it.

    Comment

    • Brian Victor

      #3
      Re: wxPython beginners problem

      Ivan Reborin wrote:
      win.Show
      This line isn't doing anything. It needs to be:
      win.Show() # note the parentheses

      --
      Brian

      Comment

      • s0suk3@gmail.com

        #4
        Re: wxPython beginners problem

        On Aug 15, 11:31 am, Ivan Reborin <ireborin@gmail .comwrote:
        Hello all,
        >
        I'm new to python, new as newbies get, so please, don't take wrongly
        if this seems like a stupid or overly simple question.
        >
        I'm going through examples in a book I have ("Beginning python", by
        Hetland Marcus) and I just started doing wxPython examples.
        >
        But every sample I try, for example:
        >
        import wx
        app = wx.App()
        win = wx.Frame(None, title="Simple editor")
        loadButton = wx.Button(win, label='Open')
        saveButton = wx.Button(win, label='Save')
        win.Show
        app.MainLoop()
        >
        There are a couple of things you're missing. Here is the fix:

        import wx

        # First of all, I'd recommend you to pass False as
        # the 'redirect' parameter, so that any errors appear
        # on the console
        app = wx.App(redirect =False)

        win = wx.Frame(None, title="Simple editor")
        loadButton = wx.Button(win, label='Open')
        saveButton = wx.Button(win, label='Save')

        # Now you need to set the frame as the top-level
        # window

        app.SetTopWindo w(frame)

        # In the line
        #
        # win.Show
        #
        # Python recognizes this as a method, but you're
        # not calling it, so its value is discarded. It's
        # a meaningless, albeit legal statement.

        win.Show()

        # Now, let the fun begin
        app.MainLoop()

        # Sebastian

        Comment

        • Mike Driscoll

          #5
          Re: wxPython beginners problem

          On Aug 15, 11:31 am, Ivan Reborin <irebo...@gmail .comwrote:
          Hello all,
          >
          I'm new to python, new as newbies get, so please, don't take wrongly
          if this seems like a stupid or overly simple question.
          >
          I'm going through examples in a book I have ("Beginning python", by
          Hetland Marcus) and I just started doing wxPython examples.
          >
          But every sample I try, for example:
          >
          import wx
          app = wx.App()
          win = wx.Frame(None, title="Simple editor")
          loadButton = wx.Button(win, label='Open')
          saveButton = wx.Button(win, label='Save')
          win.Show
          app.MainLoop()
          >
          closes too fast. After running in python IDLE just the line
          === restart ===
          shows up.
          >
          How can I keep the window to "stay alive" so I see what I get ?
          I'm on a winxp platform using python 2.5.2. if that matters.
          >
          Please, any help, constructive advice and ideas are very much
          appreciated.
          >
          Best regards
          Ivan Reborin
          See what Brian said about your issue. As for whether or not this
          toolkit is for you, that's a subjective question. Try them both and
          see which one suits you. I like wx better, but I needed its widgets
          for what I was doing and Tkinter didn't seem to have what I needed at
          the time.

          Anyway, wxPython has an excellent user's group, where you can learn
          lots and the group is nice to new people too!



          Mike

          Comment

          • David C. Ullrich

            #6
            Re: wxPython beginners problem

            In article <adbba4hok1sg0b 2d8dc1flaic8j19 7s2tj@4ax.com>,
            Ivan Reborin <ireborin@gmail .comwrote:
            Hello all,
            >
            I'm new to python, new as newbies get, so please, don't take wrongly
            if this seems like a stupid or overly simple question.
            >
            I'm going through examples in a book I have ("Beginning python", by
            Hetland Marcus) and I just started doing wxPython examples.
            >
            But every sample I try, for example:
            >
            import wx
            app = wx.App()
            win = wx.Frame(None, title="Simple editor")
            loadButton = wx.Button(win, label='Open')
            saveButton = wx.Button(win, label='Save')
            win.Show
            app.MainLoop()
            As mentioned, it should be win.Show().

            If that doesn't help, try saving it to something.py
            and executing that instead of running it inside IDLE.
            closes too fast. After running in python IDLE just the line
            === restart ===
            shows up.
            >
            How can I keep the window to "stay alive" so I see what I get ?
            I'm on a winxp platform using python 2.5.2. if that matters.
            >
            Please, any help, constructive advice and ideas are very much
            appreciated.
            >
            Best regards
            Ivan Reborin
            --
            David C. Ullrich

            Comment

            • Ivan Reborin

              #7
              Re: wxPython beginners problem

              On Fri, 15 Aug 2008 17:48:39 +0000 (UTC), Brian Victor
              <homeusenet3@br ianhv.orgwrote:
              >Ivan Reborin wrote:
              >win.Show
              >
              >This line isn't doing anything. It needs to be:
              >win.Show() # note the parentheses
              Yes, that was the problem. I must've been tired while writing it, for
              I haven't noticed it after several repetitions.
              Thank you (and everyone else on their useful comments and
              suggestions).

              Best regards
              Ivan

              Comment

              Working...