【发布时间】:2016-05-24 08:14:18
【问题描述】:
我写了这段代码,但我不明白为什么小部件 QLabel 和 QLineEdit 不显示?我必须把他们放在另一个班级吗?是 Python2.7 和 PySide。
这是我运行代码时窗口的样子:
#!/usr/bin/env python
# coding: utf-8
import sys
import crypt
from PySide import QtGui
class MyApp(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MyApp, self).__init__(parent)
self.initui()
def initui(self):
# main window size, title and icon
self.setMinimumSize(500, 350)
self.setWindowTitle("Calculate a password hash in Linux")
# lines for entering data
self.saltLabel = QtGui.QLabel("Salt:")
self.saltLine = QtGui.QLineEdit()
self.saltLine.setPlaceholderText("e.g. $6$xxxxxxxx")
# set layout
grid = QtGui.QGridLayout()
grid.addWidget(self.saltLabel, 0, 0)
grid.addWidget(self.saltLine, 1, 0)
self.setLayout(grid)
# show a widget
self.show()
def main():
app = QtGui.QApplication(sys.argv)
instance = MyApp()
instance.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
【问题讨论】:
-
您不需要
QMainWindow。您应该使用QDialog或简单地使用QWidget。
标签: qt python-2.7 pyside qlineedit qlabel