[PySide] Passing parameter from one class to an external function

Frank Rueter | OHUfx frank at ohufx.com
Thu Apr 5 00:38:03 CEST 2012


just indent your "greetings" function so it becomes a method to the 
"Form" class, then it will work.

import sys
from PySide.QtCore import *
from PySide.QtGui import *


class Form(QDialog):

     def __init__(self, parent=None):

         QDialog.__init__(self, parent=None)

         self.edit = QLineEdit("Write my name here")
         self.button = QPushButton("Show Greetings")
         self.layout = QVBoxLayout()
         self.layout.addWidget(self.edit)
         self.layout.addWidget(self.button)
         self.setLayout(self.layout)
         self.button.clicked.connect(self.greetings)


     def greetings(self):
         print ("Hello %s" % self.edit.text())


if __name__ == '__main__':
     app = QApplication(sys.argv)
     form = Form()
     form.show()
     sys.exit( app.exec_() )



On 4/5/12 10:28 AM, craf wrote:
> Hi Everyone!.
>
> Recently  start with Pyside and I would like to know how I can call the
> function greetings from within the Form class, passing the self
> argument.
>
> My Code:---------------------------------------------------
>
> import sys
> from PySide.QtCore import *
> from PySide.QtGui import *
>
>
> class Form(QDialog):
>
>      def __init__(self, parent=None):
>
>          QDialog.__init__(self, parent=None)
>
>          self.edit = QLineEdit("Write my name here")
>          self.button = QPushButton("Show Greetings")
>          self.layout = QVBoxLayout()
>          self.layout.addWidget(self.edit)
>          self.layout.addWidget(self.button)
>          self.setLayout(self.layout)
>          self.button.clicked.connect(greetings)
>
>
> def greetings(self):
>      print ("Hello %s" % self.edit.text())
>
>
> if __name__ == '__main__':
>      app = QApplication(sys.argv)
>      form = Form()
>      form.show()
>      sys.exit(app.exec_())
>
> ----------------------------------------------------
>
> I try with:
>
> self.button.clicked.connect(greetings)
> self.button.clicked.connect(lambda e: greetings(self))
> self.button.clicked.connect(lambda e, self=self:greetings(self))
>
> but, nothing.
>
> I appreciate any information
>
> Best Regards
>
> Cris
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside



More information about the PySide mailing list