wxPython Error while running.

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

wxPython Error while running.

 
0
  #1
Oct 30th, 2006
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.

  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, 0 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,135
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 946
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: wxPython Error while running.

 
0
  #2
Oct 30th, 2006
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
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1837 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC