数据可视化 第3章
第3章 创建一个空窗口
1.添加菜单栏,状态栏,
为窗口定义固定大小,或者根据当前的分辨率调整窗口大小
import sys
from PySide2.QtCore import Slot, qApp
from PySide2.QtGui import QKeySequence
from PySide2.QtWidgets import QMainWindow, QAction, QApplication
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("地震信息")
# Menu
self.menu = self.menuBar()
self.file_menu = self.menu.addMenu("文件")
# Exit QAction
exit_action = QAction("退出", self)
exit_action.setShortcut(QKeySequence.Quit)
exit_action.triggered.connect(self.close)
self.file_menu.addAction(exit_action)
# Status Bar
self.status = self.statusBar()
self.status.showMessage("数据加载和绘制")
# Window dimensions
geometry = qApp.desktop().availableGeometry(self)
self.setFixedSize(geometry.width() * 0.4, geometry.height() * 0.3)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
2.程序运行