944,165 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 2364
  • Python RSS
Oct 30th, 2006
0

wxPython Error while running.

Expand Post »
Hi, I finding difficult to execute this program. The wx.Notebook i created is coming on the splitted frame(self.p2). How do I that. I am started to learn wxPython, and when I run the code, the code doesnot close gracefully, it throughs me an error.

"pythonw.exe has encountered a problem and needs to close. We are sorry for the inconvenience"

I clicked for more information, then I got the error message which I have attached it in text file. Please help me out with this problem.

here is the code.... seems a bit lengthy, sorry about that.
Please help me to find my mistake, and how do I go forward resolving this problem.

Python Syntax (Toggle Plain Text)
  1. import wx
  2.  
  3. ID_ADD_NEW = 5001
  4. ID_DEACTIVATE = 5002
  5. ID_EXIT = 5003
  6.  
  7. class _AddNewFund(wx.Panel):
  8. def __init__(self, parent):
  9. wx.Panel.__init__(self, parent)
  10. box=wx.StaticBox(self, -1, "Add New Fund")
  11. boxsizer=wx.StaticBoxSizer(box, wx.HORIZONTAL)
  12.  
  13. t=wx.StaticText(self, -1, "Please select an Excel file to upload new funds.", (20,20))
  14. boxsizer.Add(t, 0, wx.TOP|wx.LEFT, 10)
  15. t=wx.StaticText(self, -1, "This is page one content2", (20,40))
  16. boxsizer.Add(t, 0, wx.TOP|wx.LEFT, 10)
  17.  
  18. self.text1=wx.TextCtrl(self, -1, "")
  19.  
  20. b1 = wx.Button(self, 10, " Browse ")
  21. b2 = wx.Button(self, 10, " Upload ", (60, 20))
  22. self.Bind(wx.EVT_BUTTON, self.OnBrowse, b1)
  23. self.Bind(wx.EVT_BUTTON, self.OnUpload, b2)
  24. b1.SetDefault()
  25. b1.SetSize(b1.GetBestSize())
  26. b2.SetSize(b2.GetBestSize())
  27.  
  28. grid1=wx.FlexGridSizer(0,2,0,0)
  29. grid1.Add( self.text1, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
  30. grid1.Add( b1, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
  31. #grid1.Add( b2, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
  32. border=wx.BoxSizer()
  33. border.Add(boxsizer, 1, wx.EXPAND)
  34. self.SetSizer(border)
  35. boxsizer.Add(grid1, 0, wx.ALIGN_CENTRE)
  36. border.Add(boxsizer, 0, wx.ALIGN_CENTRE)
  37. #print "end ADD NEW class"
  38.  
  39. def OnBrowse(self, event):
  40. self.dirname=""
  41. d=wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.Open)
  42. if d.ShowModal() == wx.ID_OK:
  43. self.filename=d.GetFilename()
  44. self.dirname=d.GetDirectory()
  45. self.text1.WriteTest(join(os.path.join(self.dirname, self.filename)))
  46. d.Destroy()
  47.  
  48. def OnUpload(self, event):
  49. pass
  50.  
  51. class ParentWindow(wx.Frame):
  52. def __init__(self):
  53. wx.Frame.__init__(self, None, -1, "Euro Fund manager")
  54. self.createMenu()
  55. self.Bind(wx.EVT_MENU, self.onAddnewfund, id=ID_ADD_NEW)
  56. self.Bind(wx.EVT_MENU, self.onDeactivate, id=ID_DEACTIVATE)
  57. self.Bind(wx.EVT_MENU, self.onExit, id=ID_EXIT)
  58. self.spw=wx.SplitterWindow(self)
  59. self.p1=wx.Panel(self.spw, style=wx.BORDER_NONE)
  60. self.p1.SetBackgroundColour("white")
  61. self.p2=wx.Panel(self.spw, style=wx.BORDER_NONE)
  62.  
  63. self.spw.SplitVertically(self.p1, self.p2, 200)
  64.  
  65. self.CreateStatusBar()
  66.  
  67. def createMenu(self):
  68. menu=wx.Menu()
  69. menu.Append(ID_ADD_NEW, "&Add new fund(s)", "Add new fund(s)")
  70. menu.Append(ID_DEACTIVATE, "&Deactivate fund(s)", "Deactivate fund(s)")
  71. menu.AppendSeparator()
  72. menu.Append(ID_EXIT, "E&xit", "Exit")
  73.  
  74. menubar=wx.MenuBar()
  75. menubar.Append(menu, "&File")
  76. self.SetMenuBar(menubar)
  77.  
  78. def onAddnewfund(self, event):
  79. #p=wx.Panel(self.p2)
  80. #print "panel created"
  81. nb=wx.Notebook(self.p2)
  82. #print "notebook created"
  83. addPage=_AddNewFund(nb)
  84. nb.AddPage(addPage, "Add new Fund")
  85. #print "page got added"
  86. sizer=wx.BoxSizer()
  87. sizer.Add(nb, 1, wx.EXPAND)
  88. self.p2.SetSizer(sizer)
  89. #print "end of add function"
  90.  
  91. def onDeactivate(self, event): pass
  92.  
  93. def onExit(self, event):
  94. self.Close()
  95.  
  96.  
  97. app = wx.App()
  98. frm=ParentWindow()
  99. frm.SetSize((800,500))
  100. frm.Show()
  101. app.SetTopWindow(frm)
  102. app.MainLoop()



thank you,
Regards,
kath
Attached Files
File Type: txt ERROR.txt (47.9 KB, 14 views)
Similar Threads
Reputation Points: 19
Solved Threads: 34
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006
Oct 30th, 2006
0

Re: wxPython Error while running.

Your problem is similar to one just discussed. You are adding a sizer object to a sizer object. That will lead to runtime errors. Look at Ene Uran's comments here:
http://www.daniweb.com/techtalkforums/post269933-2.html
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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 Simple Solvent Database
Next Thread in Python Forum Timeline: global or function?





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


Follow us on Twitter


© 2011 DaniWeb® LLC