PyQt5 – 如何停止调整窗口大小 | setFixedSize() 方法
在本文中,我们将看到如何停止调整主窗口的大小。在制作窗口时,我们会获得诸如全屏显示和使用光标更改其大小等选项。通过使用setFizedSize()
方法,我们可以防止调整图像的大小。
Syntax : self.setFixedSize(width, height)
Argument : It takes two integer as argument i.e width and height.
Action performed : It set the fixed size of window.
代码 :
# importing the required libraries
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
# set the title
self.setWindowTitle("Python")
width = 500
height = 400
# setting the fixed size of window
self.setFixedSize(width, height)
# creating a label widget
self.label_1 = QLabel("Fixed size window", self)
# moving position
self.label_1.move(100, 100)
# setting up the border
self.label_1.setStyleSheet("border :3px solid black;")
# resizing label
self.label_1.resize(120, 80)
# show all the widgets
self.show()
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :