WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to run this Python sample code  (Read 3199 times)

Offline zhwe1028

  • Newbie
  • *
  • Posts: 13
How to run this Python sample code
« on: June 22, 2010, 09:46:22 PM »
Hi,
I test a sample code as follows.
My question is: which packet I must to install, then I will run it ok.
thank you!

# python sample code start
#!/usr/bin/env python
#----------------------------------------------------------------------------
# Name:         test7.py
# Purpose:      A minimal wxPython test program
#
# Author:       Robin Dunn
#
# Created:      A long time ago, in a galaxy far, far away...
# Copyright:    (c) 1998 by Total Control Software
# Licence:      wxWidgets license
#----------------------------------------------------------------------------

# NOTE: this sample requires wxPython 2.6 or newer

# import the wxPython GUI package
import wx

# Create a new frame class, derived from the wxPython Frame.
class MyFrame(wx.Frame):

    def __init__(self, parent, id, title):
        # First, call the base class' __init__ method to create the frame
        wx.Frame.__init__(self, parent, id, title)

        # Associate some events with methods of this class
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_MOVE, self.OnMove)

        # Add a panel and some controls to display the size and position
        panel = wx.Panel(self, -1)
        label1 = wx.StaticText(panel, -1, "Size:")
        label2 = wx.StaticText(panel, -1, "Pos:")
        self.sizeCtrl = wx.TextCtrl(panel, -1, "", style=wx.TE_READONLY)
        self.posCtrl = wx.TextCtrl(panel, -1, "", style=wx.TE_READONLY)
        self.panel = panel

        # Use some sizers for layout of the widgets
        sizer = wx.FlexGridSizer(2, 2, 5, 5)
        sizer.Add(label1)
        sizer.Add(self.sizeCtrl)
        sizer.Add(label2)
        sizer.Add(self.posCtrl)

        border = wx.BoxSizer()
        border.Add(sizer, 0, wx.ALL, 15)
        panel.SetSizerAndFit(border)
        self.Fit()

    # This method is called by the System when the window is resized,
    # because of the association above.
    def OnSize(self, event):
        size = event.GetSize()
        self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))

        # tell the event system to continue looking for an event handler,
        # so the default handler will get called.
        event.Skip()

    # This method is called by the System when the window is moved,
    # because of the association above.
    def OnMove(self, event):
        pos = event.GetPosition()
        self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))

# Every wxWidgets application must have a class derived from wx.App
class MyApp(wx.App):

    # wxWindows calls this method to initialize the application
    def OnInit(self):

        # Create an instance of our customized Frame class
        frame = MyFrame(None, -1, "This is a test")
        frame.Show(True)

        # Tell wxWindows that this is our main window
        self.SetTopWindow(frame)

        # Return a success flag
        return True

app = MyApp(0)     # Create an instance of the application class
app.MainLoop()     # Tell it to start processing events
# python sample code end

ps:
I installed python.tcz and wxgtk.tcz throught Appbrowser successful.
Then I run this sample code,but I faild.
The error info as follows:

root@box:/mnt/sda1/sample#
root@box:/mnt/sda1/sample#python test7.py
Traceback(most recent call last):
 File "test7.py", line 16, in <module>
  import wx
ImportError:No module named wx
root@box:/mnt/sda1/sample#
« Last Edit: June 22, 2010, 09:52:23 PM by zhwe1028 »

Offline zhwe1028

  • Newbie
  • *
  • Posts: 13
Re: How to run this wxPython sample code
« Reply #1 on: June 22, 2010, 09:47:42 PM »
My Environment:
Windows 7
VMware-workstation 7.0
tinycore_2.11.5.iso

Offline althalus

  • Sr. Member
  • ****
  • Posts: 351
Re: How to run this Python sample code
« Reply #2 on: June 22, 2010, 11:11:44 PM »
You're missing wxPython. From what I can see, wxPython isn't in the repos yet, so until someone makes a wxPython package, you're out of luck.

Offline zhwe1028

  • Newbie
  • *
  • Posts: 13
Re: How to run this Python sample code
« Reply #3 on: June 22, 2010, 11:16:39 PM »
Dear althalus:
Could you make a wxPython package.
thank you

but what wxgtk.tcz  used for?
I think wxgtk.tcz is enough, but  :'(