我在Windows 64位上有python 2.7 还要将pyQt4添加到python \ 开始添加这样的代码:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class HelloWorld(QDialog):
def __init__(self):
QDialog.__init__(self)
layout = QVBoxLayout()
label = QLabel("Hello world")
line_edit = QLineEdit()
button = QPushButton("close")
layout.addWidget(label)
layout.addWidget(line_edit)
layout.addWidget(button)
self.setLayout(layout)
我从来没有看到我的代码既没有实现空白标题的空白窗口!!
答案 0 :(得分:1)
from PyQt4 import QtGui
import sys
class HelloWorld(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
layout = QtGui.QVBoxLayout()
label = QtGui.QLabel("Hello world")
line_edit = QtGui.QLineEdit()
button = QtGui.QPushButton("close")
layout.addWidget(label)
layout.addWidget(line_edit)
layout.addWidget(button)
self.setLayout(layout)
到目前为止,这么好。
要按F5添加:来测试代码
def main():
app = QtGui.QApplication(sys.argv)
hw = HelloWorld()
hw.show()
sys.exit(app.exec_())
和
if __name__ == '__main__':
main()
我建议从这里开始:http://zetcode.com/gui/pyqt4/