-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_menu_actions.py
59 lines (43 loc) · 1.74 KB
/
06_menu_actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
from PySide6.QtCore import QSize
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QApplication, QMainWindow, QToolBar, QPushButton, QStatusBar
class CustomWindow(QMainWindow):
def __init__(self, app):
super().__init__()
self.app = app
self.setWindowTitle("Custom Window")
menu_bar = self.menuBar()
file_menu = menu_bar.addMenu("&File")
new_action = file_menu.addAction("New")
quit_action = file_menu.addAction("Close")
quit_action.triggered.connect(self.quit_app)
edit_menu = menu_bar.addMenu("&Edit")
edit_menu.addAction("Copy")
edit_menu.addAction("Cut")
window_menu = menu_bar.addMenu("&Window")
window_menu.addAction("Window")
setting_menu = menu_bar.addMenu("&Others")
setting_menu.addAction("Others")
test_action = QAction("Some Act", self)
test_action.setStatusTip("This is a test action")
test_action.triggered.connect(self.test_action_triggered)
toolbar = QToolBar("Custom Toolbar", self)
toolbar.setIconSize(QSize(16, 16))
self.addToolBar(toolbar)
toolbar.addAction(new_action)
toolbar.addAction(quit_action)
toolbar.addAction(test_action)
toolbar.addSeparator()
toolbar.addWidget(QPushButton("Click here", self))
self.setStatusBar(QStatusBar(self))
def test_action_triggered(self):
print("test action is triggered")
self.statusBar().showMessage("message from custom window", 5000)
def quit_app(self):
self.app.quit()
if __name__=='__main__':
app = QApplication(sys.argv)
window = CustomWindow(app)
window.show()
app.exec()