wxPython - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

wxPython

Description:

More pythonic alternative: Connect. Adding extra controls and windows. Controls are Windows ... Not very pythonic (Wax looks promising) Choo choo! ... – PowerPoint PPT presentation

Number of Views:500
Avg rating:3.0/5.0
Slides: 14
Provided by: gnuk
Category:

less

Transcript and Presenter's Notes

Title: wxPython


1
wxPython
  • It rocks.

2
What is wxPython?
  • Python bindings over the wxWidgets C library
  • Cross platform GUI (and non-GUI) framework
  • Native look and feel backends
  • GTK 1 2 (Linux, BSDs, etc.)
  • Windows 98, 2000, XP, PocketPC, etc.
  • Mac (OS 8.6, OS 9, OS X)
  • Motif (for people who like writing ugly
    applications)
  • X11(also ugly but it works)
  • Various other non-complete ports (e.g. Palm)

3
Hardcore imagery
4
Why not just use...
  • GTK-python?
  • Weird look and feel on non-linux platforms (even
    with Wimp)
  • GTK still immature on Windows
  • PyQT?
  • It's QT
  • Tkinter?
  • Non-native look-and-feel
  • Complex layouts are difficult or impossible
  • "Why the hell hasn't wxPython become the standard
    GUI for Python yet?" -- Eric S. Raymond

5
Writing an application
  • Import wx
  • Create a wxApp instance (wx.PySimpleApp for
    convenience)
  • Begin main event loop - MainLoop()
  • Program ends after all top-level windows are gone

6
Add a frame
  • Derive a new class from wx.Frame
  • Set some defaults (title, size, etc.)
  • Add a panel child (otherwise ugly on MSW)
  • Create an instance of this class

7
Adding Menus and Statusbar
  • Create a wx.Menu for each top-level menu
  • Append(id, Name) the wx.Menu for each item in
    it
  • Create a wx.MenuBar
  • Append each menu to the menu bar.
  • Call SetMenuBar()
  • CreateStatusBar()
  • SetStatusText(text, column)
  • SetStatusWidths(...)

8
Handling menu events
  • Create a function to handle the event
  • wx.EVT_MENU(self, id, handler) to bind
  • More pythonic alternative Connect

9
Adding extra controls and windows
  • Controls are Windows
  • Create as children of a pre-existing window
  • wxPython supports absolute positioning and sizing
    (SetPosition() and SetSize()) but that's for
    chumps.
  • Use Sizers instead.

10
Sizers The Cat's Pajamas
  • Confusing at first but powerful
  • Learn to think about how controls can be nested
  • wx.BoxSizer is most common (grid style sizers are
    also availible)
  • Add(window/sizer, proportion, flags, border)
  • It'll be easier if I show you...
  • Nest sizers for sophisticated and powerful layouts

11
Dialogs
  • Modal dialogs won't let the user interact with
    the parent until the dialog is dismissed.
  • wx.FileDialog lets you get a filename to open
    from or save to.

12
Issues with wxPython
  • Fundamental platform behavioral differences
  • Windows users are rarely cool enough to have
    Python installed, let alone wxPython (py2exe
    helps)
  • Not very pythonic (Wax looks promising)

13
Choo choo!!
Write a Comment
User Comments (0)
About PowerShow.com