【发布时间】:2015-08-05 21:35:40
【问题描述】:
我想将一个字符串变量从 Main_Window 类传递给 PyQt 中的另一个 QDialog 类。我不明白我做错了什么。我想将 host_mac 变量从主类传递给 QDialog 类。这是我的代码的主要部分。
这是 QDialog 类:
class Client(QDialog):
def __init__(self, parent=None):
super(Client, self).__init__(parent)
self.pb = QPushButton()
self.pb.setObjectName("connect")
self.pb.setText("Connect")
layout = QFormLayout()
layout.addWidget(self.pb)
self.setLayout(layout)
self.connect(self.pb, SIGNAL("clicked()"),self.set_client)
self.setWindowTitle("Learning")
def set_client(self):
self.client = self.le.text()
print 'provided client mac is ' + self.client + 'and host_mac is ' + Main_window_ex.host_mac
这里是 Main_Window 类:
class Main_window_ex(QMainWindow, Ui_Main_window):
def __init__(self, parent = None):
"""
Default Constructor. It can receive a top window as parent.
"""
QMainWindow.__init__(self, parent)
self.setupUi(self)
self.host_mac = 'blah blah'
#more code beneeth
但我收到以下错误:
AttributeError: type object 'Main_window_ex' has no attribute 'host_mac'
【问题讨论】:
标签: python python-2.7 pyqt pyqt4