Join Club ShowMeDo to Learn Python!

This series is a part of Club ShowMeDo. Click to learn why you should join our club with a simple monthly subscription.

  • We teach Python and all the cool modules
  • Topics include beginner Python, GUIs, Web and Desktop Apps
  • Long, specially crafted video tutorials just for you
  • Club video tutorials extend our normal Free content
  • Save your time - we've done the research for you
  • Keep your skills up-to-date
  • Learn at your own pace, everything you need is shown to you
  • Over 12 hours of archived material are waiting for you in the club

Name: [002] Ian Ozsvald
Member: 104 months
Authored: 181 videos
Description: I am the co-founder of ShowMeDo (see http://showmedo.com/about), author of `The Screencasting Handbook <http://thescreencastinghandbook.com>`_ and the founder of the professional screencast production company `ProCasts <http://procasts.co.uk>`_: .. image:: http://procasts.co.uk/media/procasts_sma ...

Debug Tip (stdout) and wxPython Naming Conventions [ID:527] (3/14)

in series: Build a wxPython Image Viewer

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

When debugging a new wxPython application it is common for error messages to go to a separate window. If you application is buggy and crashes on startup then these error messages are lost! Here I show you how to keep track of the errors using 'App(redirect=False)'.

I also discuss some of the differences between wxPython and Python's naming conventions and give you a useful heuristic (stick with the naming convention of the library so you have consistency!).

Links - Python Style Guide, background on wx.App and the redirect=False parameter.

import wx

MAIN_WINDOW_DEFAULT_SIZE = (300,200)

class Frame(wx.Frame):
    
    def __init__(self, parent, id, title):
        style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER) # XOR to remove the resizeable border        
        wx.Frame.__init__(self, XXparent, id, title=title, size=MAIN_WINDOW_DEFAULT_SIZE, style=style)
        self.Center() # open in the centre of the screen
        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour('White') # make the background of the window white

class App(wx.App):
    
    def OnInit(self):
        self.frame = Frame(parent=None, id=-1, title='Image Viewer')
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True
    
if __name__ == "__main__":       
    # make an App object, set stdout to the console so we can see errors
    app = App()
    #app = App(redirect=False)
        
    app.MainLoop()

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 221 (since July 30th)
  • Plays in last week: 0
  • Published: 78 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>








All comments excluding tick-boxed quick-comments

I could not find the source code from ep 2, I did get the zip file w/3 images. I typed in the source. Of course had a couple of typo's, probably the only way to learn. Then in the next ep, get told how to actually see there errors I was struggling with before. The sequence of the episodes certainly did reinforce the lesson in ep 3.


Really enjoying this series, it's even better the second time around. WxPython is such a useful module; it's a pleasure to work with : )


I'm having issues with this lesson, too. I uninstalled the unicode version of wxPython and now have 2.8.7.1 (msw-ansi). I still get the behavior from lesson two where Python puts the frame back up and then hangs when I try to exit. Plus, in this episode the redirect doesn't seem to have any effect.


wxPython is a vast and complex framework. I have been working slowly, for some time, learning bits and pieces of it. A professional walk through is just what I've been waiting for. Thanks Ian!


Wow, I completely agree with Lucas, coding conventions are overlooked by most programming teachers, when it should actually be given top priority. Great stuff here Ian.


Again, an excellent episode. It was a very good idea to take a detour and talk about coding conventions because it

a) will help newbies down the road when they're writing their own apps without wxPython

b) let's the stuff from the previous episode sink in.

Good job!

Lucas


Video published, thanks for contributing to ShowMeDo


Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Ian

Content

Feedback

Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.

feedback@showmedo.com