[PyQt6] PartⅡ. QVBoxLayout
Event Handling(Signal and Slots)
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QHBoxLayout
from PyQt6.QtGui import QIcon, QFont
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(200, 200, 700, 400) # 设置窗口大小
self.setWindowTitle("Python Event Handling")
self.setWindowIcon(QIcon('images/example.jpg')) # 设置图片,没有的话不显示
self.label = QLabel("Default Text")
self.create_widget()
def create_widget(self):
hbox = QHBoxLayout()
btn = QPushButton("Change Text")
btn.clicked.connect(self.clicked_btn)
hbox.addWidget(btn)
hbox.addWidget(self.label)
self.setLayout(hbox)
def clicked_btn(self): # 定义一个点击后应该发什么什么的函数
self.label.setText("Another Text")
self.label.setFont(QFont("Times", 15))
self.label.setStyleSheet('color: red')
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec())
![](https://img2022.cnblogs.com/blog/1887969/202205/1887969-20220522155155297-1366675431.png 400300)
![](https://img2022.cnblogs.com/blog/1887969/202205/1887969-20220522155206213-562357119.png 400300)