![](/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.