python - 打开带有按钮的窗口时出现属性错误。'DataInput' 对象没有属性 'graph'
问题描述
我从 PyQt5 中的图形界面主题开始。
我已经定义了两个窗口,第一个是主窗口,另一个是包含一个按钮的子窗口,该按钮调用一个函数,通过相应事件的“单击”方法制作图形。
我的问题是,执行时出现以下错误:'DataInput' object has no attribute 'graph'。
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.uic import loadUi
import matplotlib.pyplot as plt
# CLASS MAIN WINDOW
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
class mainWindowInicial(QMainWindow):
def __init__(self, parent=None):
super(mainWindowInicial,self).__init__(parent)
loadUi('Gui/mainwindow.ui', self)
self.actionData.triggered.connect(self.open_dataInput)
# EVENTS ==================================================================
def open_dataInput(self):
DataInput(self).show()
def graphics():
plt.plot((0,5),(0,5))
plt.show()
class DataInput(QMainWindow):
def __init__(self, parent=None):
super(DataInput,self).__init__(parent)
loadUi('Gui/datawindow.ui', self)
self.pushButton_Graph.clicked.connect(self.graph)
def graph():
graphics()
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = mainWindowInicial()
widget.show()
sys.exit(app.exec_())
如果有人更了解 PyQt5,我将不胜感激您的帮助,最好的问候。
解决方案
推荐阅读
- javascript - 没有反弹css时,Javascript的scrollTo()不起作用?
- python - 如何使用 html 和 cheeypy 将对象放在隐藏的输入字段中
- magento2 - Magento 2 安全扫描显示文件可通过 HTTP 公开访问
- shell - grep if 条件下的变量
- reactjs - 使用带有 Formik 的 Rollup.JS 的外部库不尊重命名导出
- ajax - Spring MVC ajax 发布文本数据
- unity3d - LWRP 着色器在 android 中不起作用!仅在 Unity 中工作
- hadoop - Ambari:如何部署 /etc/hosts?
- ios - IOS 应用程序拒绝 ITMS-90338:非公共 API 使用 - applicationWillTerminate cordova
- java - 有人可以帮我纠正java pangram程序中的这个错误吗