Hey everyone again, so I am having a lot of problems with function in wxPython, this time, I need to know how, or if it is possible, to add new widgets to the main frame from a function, so here is my code:
import wx
class Example(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Example', size=(312,170))
panel=wx.Panel(self)
ntext=wx.StaticText(panel, -1, "Name: ", pos=(3,6))
self.name=wx.TextCtrl(panel, -1, "Your name", size=(220, -1), pos=(60,2))
self.name.SetInsertionPoint(0)
Namo=wx.Button(panel, -1, "Namo", pos=(150,50), size=(60,30))
self.Bind(wx.EVT_BUTTON, self.GetName, Namo)
def GetName(self, panel):
print(self.name.GetValue())
Quit=wx.Button(panel, -1, "Quit", pos=(50,50), size=(60,30))
self.panel.Bind(wx.EVT_BUTTON, self.closebutton, Quit)
ntext=wx.StaticText(panel, -1, "New Text: ", pos=(3,85))
self.panel.name=wx.TextCtrl(panel, -1, "Your Static Text", size=(220, -1), pos=(60,85))
self.panel.name.SetInsertionPoint(0)
def closebutton(self, panel):
self.Close(True)
if __name__ == '__main__':
app=wx.PySimpleApp()
frame=Example(parent=None,id=-1)
frame.Show()
app.MainLoop()
and when i click on the button "Namo", i get this error:
Traceback (most recent call last):
File "C:\Users\H4CkiNG\Desktop\Example\example.py", line 21, in GetName
Quit=wx.Button(panel, -1, "Quit", pos=(50,50), size=(60,30))
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 87, in __init__
_controls_.Button_swiginit(self,_controls_.new_Button(*args, **kwargs))
TypeError: in method 'new_Button', expected argument 1 of type 'wxWindow *'
And I dont really know what to do. Thanks, Dan08.