Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python PyQt5中的对话框之间发送数据_Python_Python 3.x_Pyqt_Pyqt5 - Fatal编程技术网

如何在python PyQt5中的对话框之间发送数据

如何在python PyQt5中的对话框之间发送数据,python,python-3.x,pyqt,pyqt5,Python,Python 3.x,Pyqt,Pyqt5,我尝试将spinbox的值和复选框的状态从第二个对话框发送到父对话框……但返回的值不是第二个对话框的值 这是代码 import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * __appname__ = 'Dialog app ' class Dialog(QDialog): def __init__(self, parent=None): super(Dialog, self).__init__

我尝试将spinbox的值和复选框的状态从第二个对话框发送到父对话框……但返回的值不是第二个对话框的值 这是代码

import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

__appname__ = 'Dialog app '

class Dialog(QDialog):
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)

        self.btn = QPushButton('open dialog')
        self.label1 = QLabel('Label 1 Result')
        self.label2 = QLabel('Label 2 result')

        layout = QVBoxLayout()
        layout.addWidget(self.btn)
        layout.addWidget(self.label1)
        layout.addWidget(self.label2)

        self.setLayout(layout)
        self.setWindowTitle(__appname__)


        self.btn.clicked.connect(self.dialogOpen)


    def dialogOpen(self):
        dialog = subDialog()

        self.sub = subDialog()

        self.check = str(self.sub.checkbox.isChecked())
        self.spin = str(self.sub.spinbox.value())


        if dialog.exec_():
            self.label1.setText('spinbox value is ' + self.spin)
            self.label2.setText('Checkbox is ' + self.check)


class subDialog(QDialog):
    def __init__(self, parent=None):
        super(subDialog, self).__init__(parent)

        self.setWindowTitle('Sub Dialog')

        self.checkbox = QCheckBox()
        self.spinbox = QSpinBox()
        self.buttonOK = QPushButton('Ok')
        self.buttonCancel = QPushButton('cancel')



        lay = QGridLayout()
        lay.addWidget(self.spinbox, 0, 0)
        lay.addWidget(self.checkbox, 0, 1,)
        lay.addWidget(self.buttonOK)
        lay.addWidget(self.buttonCancel)

        self.setLayout(lay)

        self.buttonOK.clicked.connect(self.accept)
        self.buttonCancel.clicked.connect(self.reject)

app = QApplication(sys.argv)
form = Dialog()
form.show()
app.exec_()
exec_u3;()
正在阻塞,因此您获取的数据是显示新窗口之前的数据,您必须获取关闭窗口的数据,即在
exec_3;()之后的数据。

exec_u3;()
正在阻塞,因此您获取的数据是显示新窗口之前的数据,您必须获取关闭窗口的数据,即在
exec_3;()之后的数据。


问题是,您甚至在打开对话框之前就读取了这些值。这只会给出初始值。打开对话框后放置读数,您会没事的

def dialogOpen(self):
    self.sub = subDialog()

    if self.sub.exec_():
        check = str(self.sub.checkbox.isChecked())
        spin = str(self.sub.spinbox.value())

        self.label1.setText('spinbox value is ' + spin)
        self.label2.setText('Checkbox is ' + check)

问题是,您甚至在打开对话框之前就读取了这些值。这只会给出初始值。打开对话框后放置读数,您会没事的

def dialogOpen(self):
    self.sub = subDialog()

    if self.sub.exec_():
        check = str(self.sub.checkbox.isChecked())
        spin = str(self.sub.spinbox.value())

        self.label1.setText('spinbox value is ' + spin)
        self.label2.setText('Checkbox is ' + check)