Foros del Web » Programando para Internet » Python »

[SOLUCIONADO] wxpython: Regresar a panel padre desde panel hijo

Estas en el tema de wxpython: Regresar a panel padre desde panel hijo en el foro de Python en Foros del Web. Tengo un frame con un panel "panel 1" cuando presiono el botón "a" me lleva a un "panel 2" con dos botones uno que me ...
  #1 (permalink)  
Antiguo 17/09/2014, 13:50
 
Fecha de Ingreso: enero-2011
Ubicación: En un Cuarto Cubierto de Pasto Verde
Mensajes: 95
Antigüedad: 13 años, 3 meses
Puntos: 3
Pregunta wxpython: Regresar a panel padre desde panel hijo

Tengo un frame con un panel "panel 1" cuando presiono el botón "a" me lleva a un "panel 2" con dos botones uno que me regresa al panel 1 "back main" y otro botón "b" que me lleva a panel 3 hasta aquí todo bien, el problema viene cuando quiero regresar desde el panel 3 al panel 1 mediante el botón "back main" pero no puedo regresar al inicio(panel 1).

one.py
Código Python:
Ver original
  1. import wx
  2.  
  3. from two import aFrame
  4.  
  5. class MainFrame(wx.Frame):
  6.     def __init__(self,parent,id):
  7.         wx.Frame.__init__(self,parent,id,'Title',size=(353,270),style=wx.CAPTION|wx.CLOSE_BOX|wx.SYSTEM_MENU|wx.MINIMIZE_BOX)
  8.         self.panel=wx.Panel(self)
  9.  
  10.         aButton= wx.Button(self.panel, -1, 'a',pos=(10,10),size=(-1,30))
  11.         self.Bind(wx.EVT_BUTTON, self.a,aButton)
  12.  
  13.     def a(self,event):
  14.         aframe=aFrame(parent=self)
  15.         aframe.Centre()
  16.         aframe.Show()
  17.         self.panel.Hide()
  18.  
  19. if __name__ == '__main__':
  20.     app=wx.App()
  21.     frame=MainFrame(parent=None,id=999)
  22.     frame.Centre()
  23.     frame.Show()
  24.     app.MainLoop()

two.py
Código Python:
Ver original
  1. import wx
  2.  
  3. from three import bFrame
  4.  
  5. class aFrame(wx.Panel):
  6.     def __init__(self, parent):
  7.         wx.Panel.__init__(self, parent, size=(353,270))
  8.  
  9.         self.parent=parent
  10.  
  11.         mainButton = wx.Button(self, -1, '&Back to Main',pos=(100,100),size=(-1,30))
  12.         self.Bind(wx.EVT_BUTTON, self.backMain,mainButton)
  13.  
  14.         bButton= wx.Button(self, -1, 'b',pos=(100,10),size=(-1,30))
  15.         self.Bind(wx.EVT_BUTTON, self.b,bButton)
  16.  
  17.     def backMain (self, event):
  18.         self.parent.Show()
  19.         self.Destroy()
  20.  
  21.     def b(self,event):
  22.         bframe=bFrame(parent=self.parent)
  23.         bframe.Centre()
  24.         bframe.Show()
  25.         self.Hide()

three.py
Código Python:
Ver original
  1. import wx
  2.  
  3. class bFrame(wx.Panel):
  4.     def __init__(self,parent):
  5.         wx.Panel.__init__(self, parent, size=(353,270))
  6.         self.parent=parent
  7.  
  8.         mainButton = wx.Button(self, -1, '&Back to Main',pos=(100,100),size=(-1,30))
  9.         self.Bind(wx.EVT_BUTTON, self.backMain,mainButton)
  10.  
  11.     def backMain (self, event):
  12.         self.Parent().Show()
  13.         #self.Show()
  14.         #window = self.GetGrandParent().GetGrandParent().Show()
  15.         #window.Show()
  16.         self.Hide()

De ante mano muchas gracias agradezco su ayuda.
  #2 (permalink)  
Antiguo 17/09/2014, 16:07
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: wxpython: Regresar a panel padre desde panel hijo

Yo lo probé y no podía regresar del panel de 2 botones al main.

Lo único que te falto fue que confundes Panel y Frame.

Código Python:
Ver original
  1. import wx
  2.  
  3. class bFrame(wx.Panel):
  4.     def __init__(self,parent):
  5.         wx.Panel.__init__(self, parent, size=(353,270))
  6.         self.parent = parent
  7.  
  8.         mainButton = wx.Button(self, -1, '&Back to Main',pos=(100,100),size=(-1,30))
  9.         self.Bind(wx.EVT_BUTTON, self.backMain,mainButton)
  10.  
  11.     def backMain (self, event):
  12.         self.parent.panel.Show()
  13.         self.Destroy()
  14.  
  15. class aFrame(wx.Panel):
  16.     def __init__(self, parent):
  17.         wx.Panel.__init__(self, parent, size=(353,270))
  18.  
  19.         self.parent=parent
  20.  
  21.         mainButton = wx.Button(self, -1, '&Back to Main',pos=(100,100),size=(-1,30))
  22.         self.Bind(wx.EVT_BUTTON, self.backMain,mainButton)
  23.  
  24.         bButton= wx.Button(self, -1, 'b',pos=(100,10),size=(-1,30))
  25.         self.Bind(wx.EVT_BUTTON, self.b,bButton)
  26.  
  27.     def backMain (self, event):
  28.         self.parent.panel.Show()
  29.         self.Destroy()
  30.  
  31.     def b(self,event):
  32.         bframe = bFrame(parent=self.parent)
  33.         bframe.Centre()
  34.         bframe.Show()
  35.         self.Destroy()
  36.  
  37. class MainFrame(wx.Frame):
  38.     def __init__(self,parent,id):
  39.         wx.Frame.__init__(self,parent,id,'Title',size=(353,270),style=wx.CAPTION|wx.CLOSE_BOX|wx.SYSTEM_MENU|wx.MINIMIZE_BOX)
  40.         self.panel = wx.Panel(self)
  41.  
  42.         aButton= wx.Button(self.panel, -1, 'a',pos=(10,10),size=(-1,30))
  43.         self.Bind(wx.EVT_BUTTON, self.a,aButton)
  44.  
  45.     def a(self,event):
  46.         aframe = aFrame(parent=self)
  47.         aframe.Centre()
  48.         aframe.Show()
  49.         self.panel.Hide()
  50.  
  51. if __name__ == '__main__':
  52.     app=wx.App()
  53.     frame=MainFrame(parent=None,id=999)
  54.     frame.Centre()
  55.     frame.Show()
  56.     app.MainLoop()

PD: Encuentra las diferencias.
  #3 (permalink)  
Antiguo 17/09/2014, 18:14
 
Fecha de Ingreso: enero-2011
Ubicación: En un Cuarto Cubierto de Pasto Verde
Mensajes: 95
Antigüedad: 13 años, 3 meses
Puntos: 3
Respuesta: wxpython: Regresar a panel padre desde panel hijo

Muchas gracias!!!, ya quedo, de hecho este problema viene de una aplicación más grande que estoy haciendo y con este ejemplo he resuelto y entendido mejor esta parte.

La magia esta en self.parent.panel.Show(),

Muchas gracias nuevamente.


Etiquetas: wxpython
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 2 personas




La zona horaria es GMT -6. Ahora son las 22:23.