반응형
/*********************************************************************************************************
-- Title : [PyQt4] Menubar 구현
-- Reference : pythonspot.com
-- Key word : 파이썬 python pyqt qt qt4 gui 메뉴바 menu menubar
*********************************************************************************************************/
# -*- coding: utf-8 -*-
import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *
# ------------------------------------------
# -- Create window
# ------------------------------------------
myApp = QApplication(sys.argv) # Create an PyQT4 application object.
w = QMainWindow() # Add menubar, need to use QMainWindow().
w.setWindowTitle('Add Menubar')
w.resize(600, 400)
# ------------------------------------------
# -- Create menu
# ------------------------------------------
bar = w.menuBar()
bar.setNativeMenuBar(True)
# bar menu
file = bar.addMenu('File')
help = bar.addMenu('Help')
# file submenu
open = QAction(QIcon('../img/open.png'), 'Open', w) # add Icon and Text
file.addAction(open)
file.addAction('&save') # add Text only
exit = QAction(QIcon('../img/exit.png'), 'Exit', w)
file.addAction(exit)
# help submenu
music = QAction(QIcon('../img/Music.png'), 'Music', w) # add Icon and Text
help.addAction(music)
help.addAction('Reference')
edit = help.addMenu("Edit")
edit.addAction("Pre")
stop = QAction(QIcon('../img/Stop.png'), 'Stop', w) # add Icon and Text
edit.addAction(stop)
edit.addAction("Next")
# ------------------------------------------
# -- Create the actions on menubar
# ------------------------------------------
exit.triggered.connect(w.close)
# ------------------------------------------
# -- Show the window and run the app
# ------------------------------------------
w.show()
myApp.exec_()
반응형