我寫了下面的python pyQT代碼來運行一個簡單的對話框應用程序。然而,這不起作用。使用pyQT的簡單GUI不起作用。爲什麼?
我使用的PyQt 5.0在Win 8 64BIT。
它根本不起作用,並且不返回任何錯誤。當我運行它時,當前的IDE(pycharm)變得模糊(這發生在一般顯示新窗口時),但是沒有顯示窗口,當我停止執行時,它返回-1。這裏是我的代碼:
from __future__ *
from sys import *
from math import *
from PyQT5.QtCore import *
from PyQT5.QtGui import *
from PyQT5.QtWidgets import *
class Form (QGuiDialog) :
def __init__(self, parent=None) :
super(Form, self).__init__(parent)
self.browser = QTextBrowser()
self.lineedit = QLineEdit("Type an Expression, then Press Enter")
self.lineedit.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
self.setLayout(layout)
self.lineedit.setFocus()
self.connect(self.lineedit, SIGNAL("returnPressed()"), self.updateGui)
self.setWindowTitle("Calculate")
def updateGui (self) :
try :
text = unicode(self.lineedit.txt())
self.browser.append("%s = <b>%s<b>" % (text, eval(text)))
except :
self.browser.append("%s is an invalid expression" % (text))
app = QCoreApplication(sys.agrv)
x = Form()
x.show()
app.exec_()
我測試了你的代碼,它仍然不起作用... –
我剛剛測試了上面的示例(來自@xndrme),它工作..可能你的路徑中有錯誤的Qt或Python?.. – Nerkyator