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

相关文章

每天迁移MySQL历史数据到历史库Python脚本

本文实例为大家分享了Python每天迁移MySQL历史数据到历史库的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python # coding:utf-8...

Python简单实现查找一个字符串中最长不重复子串的方法

本文实例讲述了Python简单实现查找一个字符串中最长不重复子串的方法。分享给大家供大家参考,具体如下: 刚结束的一个笔试题,很简单,不多说简单贴一下具体的实现: #!usr/bin...

Python判断文件和字符串编码类型的实例

python判断文件和字符串编码类型可以用chardet工具包,可以识别大多数的编码类型。但是前几天在读取一个Windows记事本保存的txt文件时,GBK却被识别成了KOI8-R,无解...

跟老齐学Python之list和str比较

相同点 都属于序列类型的数据 所谓序列类型的数据,就是说它的每一个元素都可以通过指定一个编号,行话叫做“偏移量”的方式得到,而要想一次得到多个元素,可以使用切片。偏移量从0开始,总元素数...

简单学习Python多进程Multiprocessing

简单学习Python多进程Multiprocessing

1.1 什么是 Multiprocessing 多线程在同一时间只能处理一个任务。 可把任务平均分配给每个核,而每个核具有自己的运算空间。 1.2 添加进程 Process 与线程类似,...