| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- # Only needed for access to command line arguments
- import sys
- from PyQt5.QtCore import *
- from PyQt5.QtWidgets import *
- # 自定义窗口,继承 QMainWindow
- class MainWindow(QMainWindow):
- def __init__(self, *args, **kwargs):
- super(MainWindow, self).__init__(*args, **kwargs)
- self.windowTitleChanged().connect(self.onWindowTitleChanged)
- self.windowTitleChanged().connect(lambda x: self.my_custom_fn())
- self.windowTitleChanged().connect(lambda x: self.my_custom_fn(x))
- self.windowTitleChanged().connect(lambda x: self.my_custom_fn(x, 25))
- self.setWindowTitle("My Awesome App") # 标题
- label = QLabel("THIS IS AWESOME!!!")
- label.setAlignment(Qt.AlignCenter)
- self.setCentralWidget(label)
- def contextMenuEvent(self, event):
- print("Context menu event!")
- super(MainWindow, self).contextMenuEvent(event)
- def onWindowTitleChanged(self, s):
- print(s)
- def my_custom_fn(self, a="HELLO!", b=5):
- print(a, b)
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- window = MainWindow()
- window.show() # 默认下 windows 是隐藏的
- # 开启事件循环
- app.exec_()
|