[Python-es] Variables wxpython
Gonzalo Mouriÿfffffffffff1o Pardo
gmourinopardo en yahoo.es
Sab Oct 6 23:26:52 CEST 2012
Gracias tenias razon no iba me faltaba instanciar la aplicacion.
________________________________
De: Carlos Zuniga <carlos.zun en gmail.com>
Para: La lista de python en castellano <python-es en python.org>
Enviado: Viernes 5 de octubre de 2012 18:53
Asunto: Re: [Python-es] Variables wxpython
On Fri, Oct 5, 2012 at 9:12 AM, Gonzalo Mouriÿfffffffffff1o Pardo
<gmourinopardo en yahoo.es> wrote:
> Buenas llevo mas o menos 2 semanas aprendiendo a programar en python, y me
> encuentro en una encrucijada.
> Necesito sacar información de Ventana_New (tc1) y llevarlo al
> Ventana.SetTitle, no se como podría hacerlo, gracias.
> Ahí va mi código:
>
> import wx
>
> class Aplicacion(wx.App):
>
> def OnInit(self):
> self.frame = Ventana(None, -1, title = "Control Horario")
> self.SetTopWindow(self.frame)
> self.frame.Show()
> return True
>
> class Ventana(wx.Frame):
>
> def __init__(self, parent, id, title):
> super(Ventana, self).__init__(parent, id, title, size = (800, 275))
> panel = wx.Panel(self)
> menubar = wx.MenuBar()
> arcm = wx.Menu()
> anmi = wx.MenuItem(arcm, ID_NUEVO, "&Nuevo\tCtrl+N")
> arcm.AppendItem(anmi)
> menubar.Append(arcm, '&Archivo')
> self.SetMenuBar(menubar)
> self.Bind(wx.EVT_MENU, self.OnMenu)
>
> def OnMenu(self, event):
> evt_id = event.GetId ()
> if evt_id == ID_NUEVO:
> self.frame = Ventana_New(None, -1, title = "Nuevo Usuario")
>
> class Ventana_New(wx.Frame):
>
> def __init__(self, parent, id, title):
> self.padre = parent
> wx.Frame.__init__(self, parent, id, title, size = (295, 357))
> self.panel = Panel_New(self)
> self.Show(True)
>
> class Panel_New(wx.Panel):
>
> def __init__(self, parent, *args, **kwargs):
> self.padre = parent
> wx.Panel.__init__(self, parent, *args, **kwargs)
> gs = wx.FlexGridSizer(3, 2, 9, 9)
> vbox = wx.BoxSizer(wx.VERTICAL)
> hbox = wx.BoxSizer(wx.HORIZONTAL)
> nombre = wx.StaticText(self, -1, "Nombre:")
> self.tc1 = wx.TextCtrl(self, -1, size = (150, -1))
> gs.AddMany([(nombre), (self.tc1, 1, wx.LEFT, 10)]
> self.btn = wx.Button(self, -1, 'Aceptar', size = (-1, 30))
> hbox.Add(self.btn)
> vbox.Add(hbox, 0, wx.ALIGN_CENTER | wx.BOTTOM, 10)
> self.Bind(wx.EVT_BUTTON, self.OnAceptar, id = self.btn.GetId())
> self.SetSizer(vbox)
>
> def OnAceptar(self, event):
> padre = self.GetParent()
> padre.Close(True)
>
Hola, tu ejemplo no corre así que no lo puedo probar... pero lo que
puedes hacer es añadir un evento close:
def OnMenu(self, event):
evt_id = event.GetId()
if evt_id == ID_NUEVO:
self.frame = Ventana_New(None, -1, title = "Nuevo Usuario")
self.frame.Bind(wx.EVT_CLOSE, self.OnCloseMenu)
self.frame.Show(True)
def OnCloseMenu(self, event):
print self.frame.panel.tc1.GetValue()
self.frame.Destroy()
También tendrías que chequear si solo se ha cerrado la ventana o se ha
presionado el boton Aceptar. Añade un atributo aceptado con valor
False a Ventana_New y lo cambias a True en OnAceptar. Luego en
OnCloseMenu chequeas `if self.frame.aceptado: ...`
Saludos
--
A menudo unas pocas horas de "Prueba y error" podrán ahorrarte minutos
de leer manuales.
_______________________________________________
Python-es mailing list
Python-es en python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20121006/c09bde93/attachment.html>
Más información sobre la lista de distribución Python-es