Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 25th, 2004, 05:45 PM
WheresTheAnyKey WheresTheAnyKey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 17 WheresTheAnyKey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Modules in wxPython

I am not sure how to make modules in wxpython, I can do it Python, but for some reason I'm getting a lot of problems when I try to do it in wxPython.

I made a very simple code using to files (test.py and test2.py).

The is test.py:
Code:
from wxPython.wx import *
from test2

class MainWindow(wxFrame):
    def __init__(self,parent,id,title):
        wxFrame.__init__(self,parent,wxID_ANY, title, size = (200,100))

        EVT_LEFT_DOWN(self,test2.OnClick)
        
        self.Show(true)
        
app = wxPySimpleApp()
frame = MainWindow(None, -1, "Hello")
app.MainLoop()


and this is test2.py:
Code:
from wxPython.wx import *

def OnClick(event):
    text1 = wxStaticText(self, -1, "HJJJJJJJ", (100,100))
    Show.text1(true)  


This is the error get when I open run the file in idle:
Code:
Traceback (most recent call last):
  File "C:\Documents and Settings\inuk\Desktop\Tweaks\Program\test.py", line 13, in ?
    frame = MainWindow(None, -1, "Hello")
  File "C:\Documents and Settings\inuk\Desktop\Tweaks\Program\test.py", line 8, in __init__
    EVT_LEFT_DOWN(self,test2.OnClick)
AttributeError: 'module' object has no attribute 'OnClick'


I'm a beginner, so I'm pretty sure this is simple to solve. So if anybody can help me that would be great.

Reply With Quote
  #2  
Old November 25th, 2004, 06:08 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 45 sec
Reputation Power: 10
Code:
from wxPython.wx import *
from test2


from test2... what?
This should be raising a SyntaxError before it gets any further...

Reply With Quote
  #3  
Old November 25th, 2004, 06:28 PM
WheresTheAnyKey WheresTheAnyKey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 17 WheresTheAnyKey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I can't believe I did that, but I still have problems even though i fixed that.

so test.py is now:
Code:
from wxPython.wx import *
import test2

class MainWindow(wxFrame):
    def __init__(self,parent,id,title):
        wxFrame.__init__(self,parent,wxID_ANY, title, size = (200,100))

        EVT_LEFT_DOWN(self,test2.OnClick)
        
        self.Show(true)
        
app = wxPySimpleApp()
frame = MainWindow(None, -1, "Hello")
app.MainLoop()


but i still get an error:
Code:
Traceback (most recent call last):
  File "C:\Documents and Settings\inuk\Desktop\Tweaks\Program\test2.py", line 4, in OnClick
    text1 = wxStaticText(self, -1, "HJJJJJJJ", (100,100))
NameError: global name 'self' is not defined


I've tried leaving the Parent section blank or with "none", but that doesn't work. I'm not sure exactly what to place instead of "self" or what I have to change to make "self" work, if i need to use the word "self" in the parent section.

Reply With Quote
  #4  
Old November 25th, 2004, 07:41 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
Your test2.OnClick event handler is not part of a class instance. self gets defined for you when an instance of a class is created but its scope is limited to the instance (if you have lots of class instances which self would be the right self in a global context. Methods of a class instance can use the self variable that was auto generated but normal functions wont know what it is

grimey
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #5  
Old November 25th, 2004, 07:43 PM
WheresTheAnyKey WheresTheAnyKey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 17 WheresTheAnyKey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for you help, but I'm still kinda confused of what to do

Reply With Quote
  #6  
Old November 26th, 2004, 09:13 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
Generally you would put the OnClick handler back into the main window class since it is a normally considered a method of that class and not a seperate thing at all. There is nothing to stop the handler being a wrapper to the real code in another module but if as you have it the code you want executed is managing the window that gets messy.


Code:
def ....(self,...): #Some init method you call before the window is displayed
    self.text1 = wxStaticText(self, -1, "", (100,100))
    self.text1.Show(False)

def OnClick(self, event):
    self.text1.SetLabel("Blah!!!")
    self.text1.Show(True) 
    
    ...
    anotherModule.actionCode(some paramter) 

Last edited by Grim Archon : November 26th, 2004 at 09:18 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Modules in wxPython


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT