来源:哔哩哔哩 时间:2023-06-01 08:32:18
from PyQt6.QtWidgets import *
from PyQt6.QtGui import QFont
from PyQt6.QtCore import Qt
(相关资料图)
import sys
class PyQt631(QWidget):
def __init__(self):
super().__init__()
self.font = QFont()
self.font.setFamily('宋体')
self.font.setPointSize(24)
self.initUI()
def initUI(self):
self.setWindowTitle('气轻PyQt6') # 设置窗口标题
self.resize(320, 200) # 设置窗口大小
self.setStyleSheet('background-color:#FFBBFF')
self.tag = QLabel(self) # 设置label信息
self.tag.setGeometry(10, 50, 200, 100) # 设置位置和大小
self.tag.setText('字体')
self.tag.setAlignment(Qt.AlignmentFlag.AlignCenter) # 横竖居中设置
self.tag.setFont(self.font)
self.btn = QPushButton('字体设置', self)
self.btn.setGeometry(210, 70, 100, 60)
self.btn.setStyleSheet('background-color:#66CDAA;color : #8B8682; \
font: bold large /"SimSun/";font-size:16px')
self.btn.clicked.connect(self.buttonClicked)
self.show()
def buttonClicked(self):
self.font, flag = QFontDialog.getFont(self.font,self,'选择字体')
if flag:
self.tag.setFont(self.font)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = PyQt631()
sys.exit(app.exec())
执行结果
标签:
“少年航天科普特训营”举行,VR空间站引关注