赞
踩
分别在加载用户界面(如果使用.UI文件)后或在窗口的init中加载。应该是这样的:class MyDialog(QtWidgets.QDialog):
def __init__(self):
super(MyDialog, self).__init__()
self.setFixedSize(640, 480)
如果这对你有用,请告诉我。
编辑:这是所提供的代码应如何重新格式化以工作的方式。from PyQt5 import QtWidgets
# It is considered a good tone to name classes in CamelCase.
class MyFirstGUI(QtWidgets.QDialog):
def __init__(self):
# Initializing QDialog and locking the size at a certain value
super(MyFirstGUI, self).__init__()
self.setFixedSize(411, 247)
# Defining our widgets and main layout
self.layout = QtWidgets.QVBoxLayout(self)
self.label = QtWidgets.QLabel("Hello, world!", self)
self.buttonBox = QtWidgets.QDialogButtonBox(self)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
# Appending our widgets to the layout
self.layout.addWidget(self.label)
self.layout.addWidget(self.buttonBox)
# Connecting our 'OK' and 'Cancel' buttons to the corresponding return codes
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
gui = MyFirstGUI()
gui.show()
sys.exit(app.exec_())
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。