0
我将一个按钮连接到绘制图形的方法。它按预期工作,但当我关闭图表窗口并单击按钮以再次显示图表时,没有任何反应。如何刷新,更新或断开PyQt5中的信号?
我试过refresh
,update
和disconnect
,但我找不到解决方案。我是PyQt的新手。
以下是我有:
import plot
self.btn.clicked.connect(self.showPlot)
def showPlot(self):
plot.plt.show()
代码示例
剧情模块: plot.py
import numpy as np
import matplotlib.pyplot as plt
N = 5
first_means = (20, 35, 30, 35, 27)
first_std = (2, 3, 4, 1, 2)
ind = np.arange(N)
width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(ind, first_means, width, color='r', yerr=first_std)
second_means = (25, 32, 34, 20, 25)
second_std = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind + width, second_means, width, color='y', yerr=second_std)
PyQt5模块:
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication)
import plot
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.btn = QPushButton('Show Plot', self)
self.btn.move(20, 20)
self.btn.clicked.connect(self.showPlot)
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Show Plot')
self.show()
def showPlot(self):
plot.plt.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
请提供[MCVE](https://stackoverflow.com/help/mcve)。您发布的代码不完整,并不能证明问题。你不应该改变任何信号多次工作 – user3419537
@ user3419537感谢您的评论。我认为我的原始问题被认定为MCVE,因为它描述了实际问题。但是,您说得对,另外一些示例代码可能会有所帮助。所以,我编辑了我的问题并发布了一个例子。 –