无论我在哪里执行python文件,GUI都不会打开对话框。我使用的是Windows10。是否可以在IDLE或QGIS Python控制台等中执行ist。
from __future__ import division
import sys
from PyQt4 import QtCore, QtGui, uic
qtCreatorFile = r"D:\tax_calc.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.calc_tax_button.clicked.connect(self.CalculateTax)
def CalculateTax(self):
price = int(self.price_box.toPlainText())
tax = (self.tax_rate.value())
total_price = price + ((tax / 100) * price)
total_price_string = "The total price with tax is: " + str(total_price)
self.results_window.setText(total_price_string)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
答案 0 :(得分:0)
更改
window = MyWindow()
sys.exit(app.exec_())
到
window = MyWindow()
window.show()
sys.exit(app.exec_())
答案 1 :(得分:0)
尝试使用try子句封装代码的主要部分,这样,如果出现异常,您将能够看到它
if __name__ == "__main__":
try:
app = QtGui.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
except Exception as e:
print(repr(e))