python - How to access variables from one class to another class in PyQt4? -
I want to get a string from the main window to be used in a trigger window with one click. I know how to do this by putting all the statements in the same class, but now I am trying to do the same with a square per window. This code is:
importing system from PyQt4 import QtGui class window (QtGui.QWidget): def __init __ (self, original = none): super. () .__ init (__) .initUI () Def initUI (self): self.value = QtGui.QLineEdit ('23 ') self.button = QtGui.QPushButton (' Open Dialog ') self.button.clicked.connect (self.openDialog) vbox = QtGui .QVBoxLayout () Vbox.addWidget (self.value) vbox.addWidget (self.button) self.setLayout (vbox) def openDialog (self): self.entry = self.value.text () print (self.entry) dialog (). Exec_ () Class dialog (QtGui.QDialog): def __init __ (self, parent = window): super. () .__ init (__) win = window () self.text = win.entry self.label = QtGui.QLabel (Auto text) hbox = QtGui.QHBoxLayout () hbox.addWidget (self.label) self.setLayout (hbox) def main (): app = qtGui.QApplication (sys.argv) w = window () w.show ( ) Sys. Formerly this (app.exec_ ()) if __name__ == '__main__': main () but I'm getting the error " AttributeError: any feature of the 'window' object Do not have 'entry' "and I do not know any other way to fix it. Can anyone help me with it? Make an example of dialog openDialog In this way, two sections can work more independently, and you will not need to use the window class from within dialog, so that you can directly use your attributes. category:
def openDialog (self): dialog = dialog (self) dialog.label.setText (self.value.text ()) dialog.exec_ () print (dialog .label.text ()) Class dialog (QtGui.QDialog): def __init __ (self, m Ta father = none): super. () .__ init __ (parent) self.label = QtGui.QLabel (auto) hbox = QtGui.QHBoxLayout () hbox.addWidget (self.label) self.setLayout (hbox)
Comments
Post a Comment