943,708 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 356
  • Python RSS
Mar 10th, 2009
0

Error?

Expand Post »
My error is ">>>
Traceback (most recent call last):
File "C:\Python25\Books_per_month1AP.py", line 203, in <module>
Window()
File "C:\Python25\Books_per_month1AP.py", line 7, in __init__
wxFrame.__init__ ( self, None, -1, 'Audit', size = ( 300, 300 ) )
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 505, in __init__
_windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
PyNoAppError: The wx.App object must be created first!
>>> "

What is wrong with this!?

Python Syntax (Toggle Plain Text)
  1. from wxPython.wx import *
  2.  
  3. class Window ( wxFrame ):
  4.  
  5. def __init__ ( self ):
  6.  
  7. wxFrame.__init__ ( self, None, -1, 'Audit', size = ( 300, 300 ) )
  8.  
  9. # Create a status bar
  10.  
  11. self.CreateStatusBar()
  12.  
  13. # Create a panel
  14.  
  15. self.panel = wxPanel ( self, -1 )
  16.  
  17. # Create a label
  18.  
  19. self.label = wxStaticText ( self.panel, -1, 'Nation Audit:' )
  20.  
  21. # Define a list of items to place in the wxCheckListBox
  22.  
  23. self.trade = [ 'Trade' ]
  24. self.bonus = [ 'Bonus Resources' ]
  25. self.tech15 = [ 'Technology above 15' ]
  26. self.tech51 = [ 'Tech ratio better than 5:1' ]
  27. self.soldier = [ 'Soldiers greater than 20%' ]
  28. self.soldier60 = [ 'Soldiers less than 60%' ]
  29. self.defcon = [ 'Defcon 5 (unless in war)' ]
  30. self.peace = [ 'Not in peace mode' ]
  31. self.government = [ 'Government' ]
  32. self.tank = [ 'Tanks' ]
  33. self.cm = [ 'Cruise Missles' ]
  34.  
  35. # Create a wxCheckListBox
  36.  
  37. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.trade, style = wxLB_HSCROLL )
  38. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.bonus, style = wxLB_HSCROLL )
  39. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.tech15, style = wxLB_HSCROLL )
  40. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.tech51, style = wxLB_HSCROLL )
  41. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.soldier, style = wxLB_HSCROLL )
  42. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.soldier60, style = wxLB_HSCROLL )
  43. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.defcon, style = wxLB_HSCROLL )
  44. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.peace, style = wxLB_HSCROLL )
  45. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.government, style = wxLB_HSCROLL )
  46. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.tank, style = wxLB_HSCROLL )
  47. self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = self.cm, style = wxLB_HSCROLL )
  48.  
  49. # Hook up an event handling method
  50.  
  51. EVT_CHECKLISTBOX ( self.panel, 100, self.clickHandler )
  52.  
  53. # Create a button
  54.  
  55. self.button = wxButton ( self.panel, 200, 'Audit' )
  56.  
  57. # Hook up an event handling method
  58.  
  59. EVT_BUTTON ( self.panel, 200, self.buttonHandler )
  60.  
  61. # Create two sizers to make everything pretty
  62.  
  63. # The usual
  64.  
  65. self.vertical = wxBoxSizer ( wxVERTICAL )
  66.  
  67. self.vertical.Add ( ( 0, 0 ), 1 )
  68.  
  69. self.vertical.Add ( self.label, 0, wxALIGN_CENTER )
  70.  
  71. self.vertical.Add ( ( 5, 5 ), 0 )
  72.  
  73. self.vertical.Add ( self.box, 0, wxALIGN_CENTER )
  74.  
  75. self.vertical.Add ( ( 5, 5 ), 0 )
  76.  
  77. self.vertical.Add ( self.button, 0, wxALIGN_CENTER )
  78.  
  79. self.vertical.Add ( ( 0, 0 ), 1 )
  80.  
  81. self.horizontal = wxBoxSizer ( wxHORIZONTAL )
  82.  
  83. self.horizontal.Add ( ( 0, 0 ), 1 )
  84.  
  85. self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )
  86.  
  87. self.horizontal.Add ( ( 0, 0 ), 1 )
  88.  
  89. # Attach the sizer
  90.  
  91. self.panel.SetSizerAndFit ( self.horizontal )
  92.  
  93. self.Show ( True )
  94.  
  95. # This method is called when an item is clicked
  96.  
  97. def clickHandler ( self, event ):
  98.  
  99. if self.box.IsChecked ( event.GetSelection() ):
  100.  
  101. message = ''
  102.  
  103. else:
  104.  
  105. message = ''
  106.  
  107. # Update the status bar of the window
  108.  
  109. self.SetStatusText ( self.box.GetString ( event.GetSelection() ) + message )
  110.  
  111. # This method will be called when the button is clicked
  112.  
  113. def buttonHandler ( self, event ):
  114.  
  115. message = 'Nation Audit Final:'
  116.  
  117. # Check to see what has been selected and what has not
  118.  
  119. x = 0
  120.  
  121. for choice in self.trade:
  122. if self.box.IsChecked ( x ):
  123. print
  124. else:
  125. print 'Find More Trades'
  126.  
  127. for choice in self.bonus:
  128. if self.box.IsChecked ( x ):
  129. print
  130. else:
  131. print 'Restructure your trades'
  132.  
  133.  
  134. for choice in self.tech15:
  135. if self.box.IsChecked ( x ):
  136. print
  137. else:
  138. print 'You should always have more than 15 tech'
  139.  
  140. for choice in self.tech51:
  141. if self.box.IsChecked ( x ):
  142. print
  143. else:
  144. print 'Buy tech till ratio is over 5:1'
  145.  
  146. for choice in self.soldier:
  147. if self.box.IsChecked ( x ):
  148. print
  149. else:
  150. print 'Buy more soldiers until it is 20% of pop'
  151.  
  152. for choice in self.soldier60:
  153. if self.box.IsChecked ( x ):
  154. print
  155. else:
  156. print 'Sell soldiers'
  157.  
  158. for choice in self.defcon:
  159. if self.box.IsChecked ( x ):
  160. print
  161. else:
  162. print 'Change defcon level to 5 unless in war'
  163.  
  164.  
  165. for choice in self.peace:
  166. if self.box.IsChecked ( x ):
  167. print
  168. else:
  169. print 'Make war an option'
  170.  
  171. for choice in self.government:
  172. if self.box.IsChecked ( x ):
  173. print
  174. else:
  175. print 'Change government type'
  176.  
  177. for choice in self.tank:
  178. if self.box.IsChecked ( x ):
  179. print 'Decommission tanks'
  180. else:
  181. print
  182.  
  183. for choice in self.cm:
  184. if self.box.IsChecked ( x ):
  185. print 'Decommission CM'
  186. else:
  187. print
  188.  
  189. message = message + '\n' + choice
  190.  
  191. x = x + 1
  192.  
  193. # Display a dialog
  194.  
  195. dialog = wxMessageDialog ( self, message, 'The audit is complete', style = wxOK )
  196.  
  197. dialog.ShowModal()
  198.  
  199. dialog.Destroy()
  200.  
  201. application = wxPySimpleApp()
  202.  
  203. Window()
  204.  
  205. application.MainLoop()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Rooking is offline Offline
6 posts
since Mar 2009
Mar 10th, 2009
1

Re: Error?

Google is your friend.
http://www.google.hu/search?q=wxPySi...ient=firefox-a

First url I get:
http://www.wxpython.org/docs/api/wx....App-class.html

which says in the example:
Python Syntax (Toggle Plain Text)
  1. app = wx.PySimpleApp()
  2. frame = wx.Frame(None, title='Hello World')
  3. frame.Show()
  4. app.MainLoop()

So that in your code the last lines will look like:
Python Syntax (Toggle Plain Text)
  1. application = wxPySimpleApp()
  2. w=Window()
  3. w.Show()
  4. application.MainLoop()

I hope this helps.

Please post the minimal code which produces the problem.
Please don't make topic with titles like 'I need help', 'Error?', 'Dunno what to do' etc...
Please use google, or any other search tool.
Reputation Points: 56
Solved Threads: 65
Posting Whiz in Training
slate is offline Offline
242 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: A recipe for simple file transfer between computers?
Next Thread in Python Forum Timeline: Python speed issue.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC