欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

pyqt4教程之实现windows窗口小示例分享

程序员文章站 2023-11-04 22:00:28
复制代码 代码如下:import sysfrom pyqt4 import qtgui, qtcoreclass window( qtgui.qmainwindow):&n...

复制代码 代码如下:

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_()