栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

开始在嵌入PyQT4 GUI的funcAnimation中工作

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

开始在嵌入PyQT4 GUI的funcAnimation中工作

一段时间后,我设法通过直接使用基础函数而不是使用动画包装器来重新创建动画:

import sysfrom PyQt4 import QtGui, QtCorefrom matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvasfrom matplotlib.figure import Figurefrom matplotlib.patches import Circlefrom matplotlib import animationfrom time import sleepclass Window(QtGui.QDialog): #or QtGui.QWidget ???    def __init__(self):        super(Window, self).__init__()        self.fig = Figure(figsize=(5, 4), dpi=100)        self.canvas = FigureCanvas(self.fig)        self.ax = self.fig.add_subplot(111)  # create an axis        self.ax.hold(False)  # discards the old graph        self.ax.set_aspect('equal', 'box')        self.circle = Circle((0,0), 1.0, animated=True)        self.ax.add_artist(self.circle)        self.ax.set_xlim([0, 10])        self.ax.set_ylim([-2, 2])        self.button = QtGui.QPushButton('Animate')        self.button.clicked.connect(self.animate)        # set the layout        layout = QtGui.QVBoxLayout()        layout.addWidget(self.canvas)        layout.addWidget(self.button)        self.setLayout(layout)        self.canvas.draw()        self.ax_background = self.canvas.copy_from_bbox(self.ax.bbox)    def animate(self):        self.animate_loop(0)    def animate_loop(self,begin):        for i in range(begin,10): self.canvas.restore_region(self.ax_background) self.circle.center=(i,0) self.ax.draw_artist(self.circle) self.canvas.blit(self.ax.bbox) self.canvas.flush_events() sleep(0.1)def main():    app = QtGui.QApplication(sys.argv)    ex = Window()    ex.show()    sys.exit(app.exec_())if __name__ == '__main__':    main()

也许这对您有用。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/648150.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号