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

yipeiwu_com5年前Python基础

复制代码 代码如下:

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

相关文章

Python操作mysql数据库实现增删查改功能的方法

本文实例讲述了Python操作mysql数据库实现增删查改功能的方法。分享给大家供大家参考,具体如下: #coding=utf-8 import MySQLdb class Mysq...

Python模仿POST提交HTTP数据及使用Cookie值的方法

本文实例讲述了在Python中模仿POST HTTP数据及带Cookie提交数据的实现方法,分享给大家供大家参考。具体实现方法如下: 方法一 如果不使用Cookie, 发送HTTP PO...

python实现ping的方法

本文实例讲述了python实现ping的方法。分享给大家供大家参考。具体如下: #!/usr/bin/env python #coding:utf-8 import os, sys,...

Pytorch中的VGG实现修改最后一层FC

https://discuss.pytorch.org/t/how-to-modify-the-final-fc-layer-based-on-the-torch-model/766/1...

浅析Python3中的对象垃圾收集机制

###概述 GC作为现代编程语言的自动内存管理机制,专注于两件事:1. 找到内存中无用的垃圾资源 2. 清除这些垃圾并把内存让出来给其他对象使用。 在Python中,它在每个对象中保持了...