当前位置:   article > 正文

python pyqt5 窗体自适应_PyQt5固定窗口大小

python qt5 窗口自适应大小

分别在加载用户界面(如果使用.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_())

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/985401
推荐阅读
相关标签
  

闽ICP备14008679号