Simple examples ?

Hallo all,

I'm trying to learn how to use wxpython but the code in demo is rather
difficult to work through: the examples are pretty complex, and code
calls on classes and functions defined in other parts of the demo.

Does anyone know of a collection of _simple_ examples for beginners ?
If there isn't, it
might be a good idea to make one, with everybody contributing a sample
for example.
Something to fill in the gap between the tutorial example which makes a simple
'hello world' frame and the complexity of the demo. (This could also
be the start of a serious tutorial ... ).

I don't find wxGlade or boa-constructor very satisfying, I would like
to use them once I've learned to code by hand more fluently ... (yes,
I'm using them now to create 'simple examples' to learn from).

···

--
Michele Alzetta

Michele,

You might be interested to know that most of the demo examples are
stand-alone; i.e. they will run all by themselves with minimal extras
from the main demo code (If I remember correctly, the most they pull
in is a wx.Frame to run inside).

For more examples, also see: http://wiki.wxpython.org/

···

--
============ wanna gmail account? email me ============

Best,

    Jeff

Michele Alzetta wrote:

Hallo all,

I'm trying to learn how to use wxpython but the code in demo is rather
difficult to work through: the examples are pretty complex, and code
calls on classes and functions defined in other parts of the demo.

Does anyone know of a collection of _simple_ examples for beginners ?

You should have a "samples" directory installed next to the demo dir. Take a look at samples/simple/simple.py and samples/doodle/superdoodle.py. There are other samples there too, but those are the ones intended for helping introduce the basics of wxPython to newbies.

There are also several items on the wiki:

http://wiki.wxpython.org/index.cgi/Getting_20Started
http://wiki.wxpython.org/index.cgi/ObstacleCourse
http://wiki.wxpython.org/index.cgi/How_20to_20Learn_20wxPython
http://wiki.wxpython.org/index.cgi/wxPython_20Cookbook

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Jeff Grimmett wrote:

Michele,

You might be interested to know that most of the demo examples are
stand-alone; i.e. they will run all by themselves with minimal extras
from the main demo code (If I remember correctly, the most they pull
in is a wx.Frame to run inside).

When run standalone they all import run.py which makes the frame and runs the demo sample as if it was being run from the demo framework. You can also just execute run.py with the name of the sample to load on the command line. And for fun you can add a "-s" parameter and then a PyShell frame will also be started with some things from the demo preloaded into its namespace.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks to everybody ... I hadn't realized so much wxpython stuff was
available actually.
Through the wiki I also found a link to an application - pycheckbook -
which as a GUI
is pretty much the sort of thing I'm trying to do.

By the way, the examples in the 'Crash course' don't seem to work, at
least not wih wxpython 2.4 - here is the simplest:

···

---------------------------------------------------------------------------------------
import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Hello My World")
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Show()

    def OnClose(self, evt):
        dlg = wx.MessageDialog(self, 'Are you sure you want to close My World?',
                        'Closing...', wx.YES_NO | wx.ICON_QUESTION)
        ret = dlg.ShowModal()
        dlg.Destroy()

        if ret == wx.ID_YES:
            evt.Skip()

app = wx.App(0)
MyFrame()
app.MainLoop()

-------------------------------------------------------------------------------------------

Fails with:

Traceback (most recent call last):
  File "hello.py", line 18, in -toplevel-
    app = wx.App(0)
  File "/usr/lib/python2.3/site-packages/wxPython/wx.py", line 1951, in __init__
    _wxStart(self.OnInit)
AttributeError: wxApp instance has no attribute 'OnInit'

--
Michele

Michele Alzetta wrote:

By the way, the examples in the 'Crash course' don't seem to work, at
least not wih wxpython 2.4 - here is the simplest:

---------------------------------------------------------------------------------------
import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Hello My World")
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Show()

    def OnClose(self, evt):
        dlg = wx.MessageDialog(self, 'Are you sure you want to close My World?',
                        'Closing...', wx.YES_NO | wx.ICON_QUESTION)
        ret = dlg.ShowModal()
        dlg.Destroy()

        if ret == wx.ID_YES:
            evt.Skip()

app = wx.App(0)
MyFrame()
app.MainLoop()

-------------------------------------------------------------------------------------------

Fails with:

Traceback (most recent call last):
  File "hello.py", line 18, in -toplevel-
    app = wx.App(0)
  File "/usr/lib/python2.3/site-packages/wxPython/wx.py", line 1951, in __init__
    _wxStart(self.OnInit)
AttributeError: wxApp instance has no attribute 'OnInit'

wxPython 2.5.x is needed to use a bare wx.App (without deriving and adding an OnInit method) and also for the Bind(...) method. For 2.4 it would look something like this:

import wx

class MyFrame(wx.Frame):
     def __init__(self):
         wx.Frame.__init__(self, None, -1, "Hello My World")
         wx.EVT_CLOSE(self, self.OnClose)
         self.Show()

     def OnClose(self, evt):
         dlg = wx.MessageDialog(self, 'Are you sure you want to close My World?',
                         'Closing...', wx.YES_NO | wx.ICON_QUESTION)
         ret = dlg.ShowModal()
         dlg.Destroy()

         if ret == wx.ID_YES:
             evt.Skip()

app = wx.PySimpleApp(0)
MyFrame()
app.MainLoop()

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Jeff Grimmett wrote:

You might be interested to know that most of the demo examples are
stand-alone; i.e. they will run all by themselves with minimal extras
from the main demo code (If I remember correctly, the most they pull
in is a wx.Frame to run inside).

Yes, but they do often pull stuff from wx.lib, which is not a big deal, but it makes them somewhat less self contained.

Over the years, I've collected a bunch of small demos, each designed to demo/test one small aspect of wxPython. Many of these were the result of questions asked on this list. Some are all my code, some are code posted by others, and fixed/changed by me. I've been meaning to clean them up and test them, and then put them all somewhere, like perhaps the Wiki. In the meantime, I've enclosed a zip file of the whole pile.

As these have been written over a period of years, they are a weird mishmash of styles and some work with 2.4, some 2.5, no guarantees. IF they work at all, they were only tested under Linux/wxGTK. It might, in fact, be a good exercise for someone to test and get them all running under 2.5.

Anyway, I've enclosed the whole pile, as it stands, as a zip file.

-Chris

wxPythonDemos.zip (60.6 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Wow, thanks !

···

On Wed, 29 Dec 2004 11:12:49 -0800, Chris Barker <Chris.Barker@noaa.gov> wrote:

Over the years, I've collected a bunch of small demos, each designed to
demo/test one small aspect of wxPython.

Anyway, I've enclosed the whole pile, as it stands, as a zip file.

--
Michele

Michele Alzetta wrote:

···

On Wed, 29 Dec 2004 11:12:49 -0800, Chris Barker <Chris.Barker@noaa.gov> wrote:

Anyway, I've enclosed the whole pile, as it stands, as a zip file.

Wow, thanks !

If you fix any of them to work with the latest version, please let me know.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov