pyqt4教程之实现windows窗口小示例分享
代码如下:
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_()
相关推荐
OldBigBrother 2020-11-09
追逐阳光的风 2020-07-04
王磊的程序员之路 2020-05-15
JimyFengqi 2020-02-17
hustlei 2020-02-01
hustlei 2020-01-29
lianback 2020-01-11
追逐阳光的风 2020-01-05
shengge0 2019-12-31
lianback 2019-12-30
Airuio 2019-12-05
hustlei 2011-03-03
OldBigBrother 2019-06-19
Eppley 2019-06-19