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

Maleah ·
更新时间:2024-11-15
· 788 次阅读

代码如下:
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_()

您可能感兴趣的文章:Pyqt实现无边框窗口拖动以及窗口大小改变PyQt5实现无边框窗口的标题拖动和窗口缩放PyQt5每天必学之创建窗口居中效果PyQt5每天必学之关闭窗口PyQt5每天必学之QSplitter实现窗口分隔PyQt5主窗口动态加载Widget实例代码PyQT实现多窗口切换



pyqt4 程之 示例 pyqt windows 教程

需要 登录 后方可回复, 如果你还没有账号请 注册新账号