wxpython - why can't I access the variable in my class. python -
i created panel in main class. wanted create button goes panel. created seperate class button called panel_in_button , set main in parameters in hopes inherit panel in main class , utilize in panel_in_button class odd reason button won't show when run program. programme runs fine exception of that. help please. here error dont think has why can't access panel.
warning (from warnings module): file "c:\python27\gui practice.py", line 19 app=wx.pysimpleapp() #this runs programme wxpydeprecationwarning: using deprecated class pysimpleapp.
import wx class main(wx.frame): def __init__(self,parent,id): wx.frame.__init__(self,parent,id, "my window", size=(300, 200)) panel=wx.panel(self) class panel_in_button(main): def __init__(self): button = wx.button(main.panel, label="exit",pos=(130,10), size=(60, 60)) self.bind(wx.evt_button, self.closebutton, button) self.bind(wx.evt_close, self.closewindow) def closebutton(self, event): self.close(true) def closewindow(self, event): self.destroy() if __name__=="__main__": app=wx.pysimpleapp() #this runs programme frame=main(parent=none, id=-1)#displays programme frame.show() app.mainloop()
you can't write code way. main class, not instance of class. shouldn't phone call class's method directly. instead, need instantiate , phone call object's method. no in code instantiate panel_in_button. anyway, don't recommend programming way. here's cleaned version:
import wx class main(wx.frame): def __init__(self,parent,id): wx.frame.__init__(self,parent,id, "my window", size=(300, 200)) panel=wx.panel(self) button = wx.button(panel, label="exit",pos=(130,10), size=(60, 60)) self.bind(wx.evt_button, self.closebutton, button) self.bind(wx.evt_close, self.closewindow) def closebutton(self, event): self.close(true) def closewindow(self, event): self.destroy() if __name__=="__main__": app=wx.app(false) #this runs programme frame=main(parent=none, id=-1)#displays programme frame.show() app.mainloop() this combines 2 classes one. replaced reference wx.pysimpleapp deprecated. recommend take @ sizers instead of absolute positioning. sizers worth effort learn.
python wxpython
No comments:
Post a Comment