Copy Code code as follows:
Import Sys
From PYQT4 import Qtgui, Qtcore
Class Window (Qtgui.qmainwindow):
def __init__ (self):
Qtgui.qmainwindow.__init__ (self)
Self.setwindowtitle (' Hello ')
Self.resize (800,500)
menubar = Self.menubar ()
Self.file = Menubar.addmenu (' &file ')
Open = self.file.addAction (' open ')
Self.connect (Open,qtcore.signal (' triggered () '), self. OnOpen)
Save =self.file.addaction (' save ')
Self.connect (Save,qtcore.signal (' triggered () '), self. OnSave)
Self.file.addSeparator ()
Close = self.file.addAction (' Close ')
Self.connect (Close,qtcore.signal (' triggered () '), self. OnClose)
Self.label = Qtgui.qlabel (' This is a Google text ')
Self.label.setAlignment (QtCore.Qt.AlignCenter)
Self.setcentralwidget (Self.label)
def OnOpen (self):
Self.label.setText (' open ')
def OnClose (self):
Self.close ()
def OnSave (self):
Self.label.setText (' Save ')
def contextmenuevent (self,event):
Self.file.exec_ (Event.globalpos ())
App =qtgui.qapplication (SYS.ARGV)
Win = Window ()
Win.show ()
APP.EXEC_ ()