hello,

i want to utilize the demo code given in the wxpython 2.8 documentation & demos.
can any one guide me how can i do that???
when i try to copy that code to editor to change it according to my requirements ..it gives me an error message and close the editor without giving any message...

any onw ho knows how to edit those demo codes please let me know..your help will be highly appreciated...
Regards,
punter

Dani AI

Generated

Most wxPython demo files are written to run inside the demo package, not as stand‑alone scripts. The ImportError "no package named run" means the demo expects a local module (the demo runner) that is not on your PYTHONPATH. That is why copying a single demo .py into another folder can fail or make your editor appear to crash — the exception is raised but you may not see the traceback if you launched the file by double‑clicking.

Practical options:

  • Run the demo from the demo tree (the demo runner provides the environment and imports). Start it from a console so you can read errors: python path\to\demofile.py.
  • Add the demo root to PYTHONPATH or copy the demo package (including the run module) into your project so the import resolves.
  • Extract only the widget code you need: remove the demo‑runner import (the run line) and any calls to the demo runner, then bootstrap the example yourself by creating a simple wx.App, instantiating the demo Frame/Panel, calling Show() and MainLoop(). Also copy any resource files the demo uses (images, data).

Debugging tips: run the script from a terminal to get the full traceback instead of relying on the editor. If the demo was written for wxPython 2.8 / Python 2, expect small compatibility edits for newer Python or Phoenix (wxPython 4.x).

This follows ’s advice to extract only the parts you need, agrees with that run lives in the demo directory, and echoes ’s warning that pulling usable snippets from the full demo can be fiddly. For background on how Python finds modules see the import system docs and for wxPython releases and migration notes see the official site: Python import systemwxPython.

Recommended Answers

All 6 Replies

You have to understand the basic of wxpython.
Then you use only the part of code that you need.

Examlpe.

import wx

class MyFrame(wx.Frame):
    '''info abot class | Doc string'''
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
         
        #---| Window color |---#
        self.SetBackgroundColour('light blue')
        
        #---| Panel for frame |---#
        self.panel = wx.Panel(self)       
        

if __name__ == "__main__":
    app = wx.App()   
    mytitle = 'My window'  
    width = 300
    height = 200
    MyFrame(None, mytitle, (width, height)).Show()
    app.MainLoop()

Now i have a basic window.
So start wxpython demo.
I what to use choicebox code from demo.
Now i only copy the part i need,not all demo code.

import wx

class MyFrame(wx.Frame):
    '''info abot class | Doc string'''
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
         
        #---| Window color |---#
        self.SetBackgroundColour('light blue')
        
        #---| Panel for frame |---#
        self.panel = wx.Panel(self)          
        
        #Demo code
        sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
                      'six', 'seven', 'eight']        
        #Demo code
        self.ch = wx.Choice(self.panel, -1, (100, 50), choices = sampleList)
        self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)

    #Demo code 
    def EvtChoice(self, event):
        a = event.GetString()  #I change event handling like this i dont wanne write out like in the demo      
        self.a = wx.StaticText(self.panel, -1, str(a), pos = (105,80))  

if __name__ == "__main__":
    app = wx.App()   
    mytitle = 'My window'  
    width = 300
    height = 200
    MyFrame(None, mytitle, (width, height)).Show()
    app.MainLoop()

There is a module that is imported that is on wxDemo DIR. I don't remember well but it is something like run
You should modify that

yes you right as i try to run the demo code in the editor it gives me an error which is as follows
no package name run
and after this error the editor close down...

can you guide me how can i modify that run module???

post whole code from demo and say which part you want so that someone can guide you on that. I don't even have Python installed here

Pulling usable code out the wxPython demo code is a royal pain. However, there are a lot of nicely working examples here:
http://www.daniweb.com/forums/thread128350.html

Tell us which widget of the demo you are interested in and we can try to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.