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_()
上一篇: 茶树菇煲鸡,你离满血复活还差一碗鸡汤