Foros del Web » Programando para Internet » Python »

Problema PyQt4

Estas en el tema de Problema PyQt4 en el foro de Python en Foros del Web. tengo un programa hecho en wxPython, y quiero tambien hacerlo en PyQt4, el problema es que no me abre la ventana desde la ventana principal, ...
  #1 (permalink)  
Antiguo 23/02/2012, 17:56
 
Fecha de Ingreso: diciembre-2011
Mensajes: 26
Antigüedad: 12 años, 4 meses
Puntos: 5
Pregunta Problema PyQt4

tengo un programa hecho en wxPython, y quiero tambien hacerlo en PyQt4, el problema es que no me abre la ventana desde la ventana principal, aqui les dejo los codigos espero me puedan ayudar.

wxPython:
Código Python:
Ver original
  1. import wx
  2.  
  3. class Editor(wx.Frame):
  4.     def __init__(self, parent, id, title):
  5.         wx.Frame.__init__(self, parent, id, title, size=(600, 500))
  6.  
  7.         menubar = wx.MenuBar()
  8.  
  9.         file = wx.Menu()
  10.         new = wx.MenuItem(file, 101, '&New\tCtrl+N', 'Creates a new document')
  11.         file.AppendItem(new)
  12.  
  13.         menubar.Append(file, '&File')
  14.         self.SetMenuBar(menubar)
  15.  
  16.         self.Bind(wx.EVT_MENU, self.NewApplication, id=101)
  17.  
  18.         self.text = wx.TextCtrl(self, 1000, '', size=(-1, -1), style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER)
  19.         self.text.SetFocus()
  20.  
  21.         self.Bind(wx.EVT_CLOSE, self.QuitApplication)
  22.  
  23.         self.Centre()
  24.         self.Show(True)
  25.  
  26.     def NewApplication(self, event):
  27.         editor = Editor(None, -1, 'Editor')
  28.         editor.Centre()
  29.         editor.Show()
  30.        
  31.     def QuitApplication(self, event):
  32.         self.Destroy()
  33.  
  34. app = wx.App()
  35. Editor(None, -1, 'Editor')
  36. app.MainLoop()

PyQt4:
Código Python:
Ver original
  1. import sys
  2. from PySide import QtGui, QtCore
  3.  
  4. class Editor(QtGui.QMainWindow):
  5.     def __init__(self):
  6.         QtGui.QMainWindow.__init__(self)
  7.        
  8.         self.setWindowTitle("Editor")
  9.         self.resize(600, 500)
  10.        
  11.         new = QtGui.QAction("New", self)
  12.         new.setShortcut("Ctrl+N")
  13.         new.triggered.connect(self.NewApplication)
  14.        
  15.         menubar = self.menuBar()
  16.         file = QtGui.QMenu("File", self)
  17.         file.addAction(new)
  18.         menubar.addMenu(file)
  19.        
  20.         self.setMenuBar(menubar)
  21.    
  22.     def NewApplication(self):
  23.         e = Editor()
  24.         e.show()
  25.  
  26. app = QtGui.QApplication(sys.argv)
  27. e = Editor()
  28. e.show()
  29. sys.exit(app.exec_())

el problema figura en que la ventana que tiene que crearse en PyQt4 se abre pero se vuelve a cerrar a diferencia de wxPython, espero me puedan ayudar.

  #2 (permalink)  
Antiguo 23/02/2012, 23:04
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: Problema PyQt4

El problema es que no estas usando PyQt4 si no que estas usando PySide.

Aquí un listado oficial de diferencias.

Ahora tu problema es el mismo que el de esta pregunta. La referencia a la nueva ventana esta siendo olvidada y por lo tanto no funciona como debería. Para solucionar eso solo guarde la referencia a la nueva ventana.

Código Python:
Ver original
  1. import sys
  2. from PySide import QtGui, QtCore
  3.  
  4. class Editor(QtGui.QMainWindow):
  5.     def __init__(self):
  6.         QtGui.QMainWindow.__init__(self)
  7.  
  8.         self.setWindowTitle("Editor")
  9.         self.resize(600, 500)
  10.  
  11.         new = QtGui.QAction("New", self)
  12.         new.setShortcut("Ctrl+N")
  13.         new.triggered.connect(self.NewApplication)
  14.  
  15.         menubar = self.menuBar()
  16.         file_menu = QtGui.QMenu("File", self)
  17.         file_menu.addAction(new)
  18.         menubar.addMenu(file_menu)
  19.  
  20.         self.setMenuBar(menubar)
  21.  
  22.     def NewApplication(self):
  23.         self.e = Editor()
  24.         self.e.show()
  25.  
  26. app = QtGui.QApplication(sys.argv)
  27. e = Editor()
  28. e.show()
  29. sys.exit(app.exec_())
  #3 (permalink)  
Antiguo 24/02/2012, 11:21
 
Fecha de Ingreso: diciembre-2011
Mensajes: 26
Antigüedad: 12 años, 4 meses
Puntos: 5
Respuesta: Problema PyQt4

GRACIASSSS !!!!!!


Etiquetas: gui, pyqt, pyqt4
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




La zona horaria es GMT -6. Ahora son las 18:09.