![](/img/trans.png)
[英]PyQt4 Qtreewidget - get hierarchy text if child checkbox is checked
[英]Showing plots if checkbox is checked, on python (with PyQt4)
我是Python的新手,正在尝试使用PyQt4编写我的第一个程序。 我的问题基本上是以下内容:我的课堂上有两个复选框(Plot1和Plot2)和一个“ End”按钮。 当我按End键时,我只想查看用户使用matplotlib检查的图。 我无法做到这一点。 我的第一个想法是:
self.endButton.clicked.connect(self.PlotandEnd)
self.plot1Checkbox.clicked.connect(self.Plot1)
self.plot2Checkbox.clicked.conncet(self.Plot2)
def PlotandEnd(self)
plot1=self.Plot1()
pyplot.show(plot1)
plot2=self.Plot2()
pyplot.show(plot2)
def Plot1(self)
plot1=pyplot.pie([1,2,5,3,2])
return plot1
def Plot2(self)
plot2=pyplot.plot([5,3,5,8,2])
return plot2
当然,这是行不通的,因为“ PlotandEnd”将绘制两个图形,而与各个复选框无关。 我该怎么做?
将绘图创建内容包装在if语句中,该语句查看复选框的状态。 例如:
def PlotandEnd(self)
if self.plot1Checkbox.isChecked():
plot1=self.Plot1()
pyplot.show(plot1)
if self.plot2Checkbox.isChecked():
plot2=self.Plot2()
pyplot.show(plot2)
您也不需要以下几行:
self.plot1Checkbox.clicked.connect(self.Plot1)
self.plot2Checkbox.clicked.conncet(self.Plot2)
目前,此操作无济于事! Qt从不使用PlotX()
方法的返回值,并且您只希望单击“结束”按钮时发生事情,而不希望单击复选框。 PlotX()
方法当前仅对您的PlotandEnd()
方法有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.