我正在从xml文件导入一些数据(netSales),我希望将此数字与“目标值”进行比较,让我们将其指定为100。
我的代码如下(来自PyQT进度条教程加上我自己的一些代码):
import sys
from PyQt4 import QtGui, QtCore
import xml.etree.ElementTree as ET
class Window(QtGui.QMainWindow):
def __init__(self,goal=100000):
super(Window, self).__init__()
self.setGeometry(50, 50, 500, 300)
self.setWindowTitle("Maar Dis Lekker!")
self.setWindowIcon(QtGui.QIcon('sales.png'))
extractAction = QtGui.QAction("&GET TO THE CHOPPAH!!!", self)
extractAction.setShortcut("Ctrl+Q")
extractAction.setStatusTip('Leave The App')
extractAction.triggered.connect(self.close_application)
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
fileMenu.addAction(extractAction)
self.goal = goal
self.home()
def home(self):
btn = QtGui.QPushButton("Quit", self)
btn.clicked.connect(self.close_application)
btn.resize(btn.minimumSizeHint())
btn.move(0,100)
label = QtGui.QLabel(self)
pixmap = QtGui.QPixmap('BuildIt.png')
label.setPixmap(pixmap)
label.resize(label.minimumSizeHint())
label.move(20,175)
extractAction = QtGui.QAction(QtGui.QIcon('todachoppa.png'), 'Flee the Scene', self)
extractAction.triggered.connect(self.close_application)
self.toolBar = self.addToolBar("Extraction")
self.toolBar.addAction(extractAction)
checkBox = QtGui.QCheckBox('Shrink Window', self)
checkBox.move(100, 25)
checkBox.stateChanged.connect(self.enlarge_window)
self.progress = QtGui.QProgressBar(self)
self.progress.setGeometry(100, 80, 350, 80)
self.show()
def calculate(self):
currentNetSales = self.getSalesData()
while self.completed < self.goal:
self.completed += 0.0001
self.progress.setValue(self.completed)
def enlarge_window(self, state):
if state == QtCore.Qt.Checked:
self.setGeometry(50,50, 1000, 600)
else:
self.setGeometry(50, 50, 500, 300)
def close_application(self):
choice = QtGui.QMessageBox.question(self, 'Extract!',
"Get into the chopper?",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if choice == QtGui.QMessageBox.Yes:
print("Extracting Naaaaaaoooww!!!!")
sys.exit()
else:
pass
def getSalesData(self):
tree = ET.parse('barSales.xml')
root = tree.getroot()
for row in root.findall(".//RECORD/ROW"):
netSales = [float(row.attrib["nettsales"])]
return netSales
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run()
问题:如何让条形图显示netSales相对于goalSales的百分比?