我正在制作一个我正在制作的脚本的GUI,经过研究我发现pyqt会有所帮助.我现在已经在pyqt中创建了一个没有工作按钮的GUI,但是想查看代码.
我打开cmd.exe并键入:
pyuic4 project.ui -o python.py
Run Code Online (Sandbox Code Playgroud)
它创建了一个python.py脚本,它向我展示了我需要的所有脚本,但是当我通过IDLE或命令提示符运行它时,它显示它正在运行但没有GUI打开.难道我做错了什么?
另外一点是,pyqt适合用于为Windows创建一个简单的GUI,还是用于移动开发?
这是我要编译和运行的代码片段
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_FileHash(object):
def setupUi(self, FileHash):
Run Code Online (Sandbox Code Playgroud)
查看本教程,了解如何使用pyuic4命令生成的代码;
基本上,你需要这样做:
import sys
from PyQt4.QtGui import QApplication, QDialog
from ui_project import Ui_Name # here you need to correct the names
app = QApplication(sys.argv)
window = QDialog()
ui = Ui_Name()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
Pyqt完全适合在Windows上创建GUI.