Note that there are some explanatory texts on larger screens.

plurals
  1. POPyqt passing parameters to a form based on user action
    text
    copied!<p>I have a form and a popup form as given below (partial code):</p> <pre><code>import sys import subprocess import os from PyQt4 import QtCore, QtGui from ui_auto import Ui_Form from popup_ui import Ui_Form as fm class MyPopupForm(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = fm() self.ui.setupUi(self) class MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Form() self.ui.setupUi(self) def when_pressed(self): self.mypopup=MyPopupForm() self.mypopup.show() def when_stopped(self): self.mypopup=MyPopupForm() self.mypopup.show() </code></pre> <p>Myform is my main form and MyPopupForm is the popup form. I need to do in such a way that, when I press a button it will print some string and display that string. When I press another button i have to invoke the same form but with different string. How could I do that (I used Qtdesigner to create UI)</p> <p>MyPopupForm code in python:</p> <pre><code># -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'popup.ui' # # Created: Sun Jan 8 11:18:43 2012 # by: PyQt4 UI code generator 4.7.3 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(207, 170) self.pushButton = QtGui.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(60, 120, 92, 27)) self.pushButton.setObjectName("pushButton") self.label = QtGui.QLabel(Form) self.label.setGeometry(QtCore.QRect(58, 30, 81, 41)) #self.label.setText("") self.label.setObjectName("label") self.retranslateUi(Form) QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), Form.close) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8)) self.pushButton.setText(QtGui.QApplication.translate("Form", "OK", None, QtGui.QApplication.UnicodeUTF8)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload