前提

1、已安装Python(环境Win7+Python 2.7.12 )

2、已安装插件pyqt4(插件获取路径:https://pan.baidu.com/s/1i50wAOH)

步骤

1、打开py designer制作界面(C:\Python27\Lib\site-packages\PyQt4\designer.exe)。

图1 designer主界面

2、选择Widget窗体形式,点击创建,设置3个Push Button和1个textEdit,并修改控件文本名称和对象名称。

图2 改变文本名称和对象名称的方法

图3 设计结果图

3、保存,设置文件名为Example_edit.ui(C:\Python27\Lib\site-packages\PyQt4\Example_edit.ui)

4、使用pyuic编译ui文件为py文件。

c:\Python27\Lib\site-packages\PyQt4>pyuic4 Example_edit.ui > Example_edit.py

c:\Python27\Lib\site-packages\PyQt4>

打开Example_edit.py文件,具体内容如下:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Example_edit.ui'
#
# Created: Mon May 01 07:32:43 2017
#      by: PyQt4 UI code generator 4.8.5
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(617, 401)
        Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.open = QtGui.QPushButton(Form)
        self.open.setGeometry(QtCore.QRect(130, 70, 91, 31))
        self.open.setText(QtGui.QApplication.translate("Form", "打开", None, QtGui.QApplication.UnicodeUTF8))
        self.open.setObjectName(_fromUtf8("open"))
        self.save = QtGui.QPushButton(Form)
        self.save.setGeometry(QtCore.QRect(300, 70, 81, 31))
        self.save.setText(QtGui.QApplication.translate("Form", "保存", None, QtGui.QApplication.UnicodeUTF8))
        self.save.setObjectName(_fromUtf8("save"))
        self.close = QtGui.QPushButton(Form)
        self.close.setGeometry(QtCore.QRect(440, 70, 81, 31))
        self.close.setText(QtGui.QApplication.translate("Form", "关闭", None, QtGui.QApplication.UnicodeUTF8))
        self.close.setObjectName(_fromUtf8("close"))
        self.textEdit = QtGui.QTextEdit(Form)
        self.textEdit.setGeometry(QtCore.QRect(90, 130, 441, 241))
        self.textEdit.setObjectName(_fromUtf8("textEdit"))

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        pass

5、建立test.py文件,编写调用和UI的操作。

#--*-- coding:utf-8--

import sys
from PyQt4 import QtCore, QtGui
from Example_edit import Ui_Form 

class StartQt4(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        QtCore.QObject.connect(self.ui.open,QtCore.SIGNAL("clicked()"),self.file_dialog)
        QtCore.QObject.connect(self.ui.save,QtCore.SIGNAL("clicked()"),self.file_save) 

    def file_save(self):   #保存文件
        from os.path import isfile
        if isfile(self.filename):
            file = open(self.filename,'w')
            file.write(self.ui.textEdit.toPlainText())
            file.close() 

    def file_dialog(self):  #打开文件操作
        fd = QtGui.QFileDialog(self)
        self.filename = fd.getOpenFileName()
        from os.path import isfile
        if isfile(self.filename):
            text = open(self.filename).read()
            self.ui.textEdit.setText(text) 

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = StartQt4()
    myapp.show()
    sys.exit(app.exec_())

6、测试结果,结束

c:\Python27\Lib\site-packages\PyQt4>python test.py

Py designer 小程序实现实例的更多相关文章

  1. 微信小程序web-view实例

    微信小程序web-view实例 index.js //index.js //获取应用实例 const app = getApp() Page({ /** * 页面的初始数据 */ data: { }, ...

  2. 微信小程序入门实例之记事本

    主要实现思想都在代码的注释中,项目源码见github 首先上项目目录 app.js文件代码如下: //app.js App({ onLaunch: function() { //调用API从本地缓存中 ...

  3. 微信小程序-weui实例代码提取

    搜索框 对应代码如下: wxss文件 <view class="page"> <view class="page__hd"> <v ...

  4. 微信小程序开发入门

    微信小程序 首先说下结构吧,看看小程序到底长什么样子 这是一个微信提供的自己的开发工具,相当于xcode吧,由此也可以看出腾讯的野心并不小啊,左边的就是编辑调试什么的,往右就是一个模拟器,你可以选择i ...

  5. 微信小程序教学第二章:小程序中级实战教程之预备篇 - 项目结构设计 |基于最新版1.0开发者工具

    iKcamp官网:http://www.ikcamp.com 访问官网更快阅读全部免费分享课程:<iKcamp出品|全网最新|微信小程序|基于最新版1.0开发者工具之初中级培训教程分享>. ...

  6. 微信小程序个人心得

    尊重原创:http://blog.csdn.net/qq_28832135/article/details/52796048 昨天看了一下微信小程序官方文档,总结一下自己学习的个人心得. 首先从官方文 ...

  7. 用Vue.js开发微信小程序:开源框架mpvue解析

    前言 mpvue 是一款使用 Vue.js 开发微信小程序的前端框架.使用此框架,开发者将得到完整的 Vue.js 开发体验,同时为 H5 和小程序提供了代码复用的能力.如果想将 H5 项目改造为小程 ...

  8. 微信小程序心得

    首先从官方文档给的框架说起,微信小程序官方文档给出了app.js, app.json, app.wxss. 先从这三个文件说起. - app.js 这个文件是整个小程序的入口文件,开发者的逻辑代码在这 ...

  9. 微信小程序踩坑集合

    1:官方工具:https://mp.weixin.qq.com/debug/w ... tml?t=1476434678461 2:简易教程:https://mp.weixin.qq.com/debu ...

随机推荐

  1. bootstraptable学习(2)分页

    1.分页需要配置一些参数 function init() { $('#bootstrapModel').bootstrapTable({ url: "../Listing.ashx" ...

  2. 结合源码分析 bubble 使用注意事项

    使用dubbo时候要尽量了解源码,不然会很容易入坑. 一.服务消费端ReferenceConfig需要自行缓存 ReferenceConfig实例是个很重的实例,每个ReferenceConfig实例 ...

  3. MVC 访问静态页面 View 下面放JS

    http://blog.csdn.net/qq_17255515/article/details/53293120

  4. 13-001 ViewComponents IViewComponentActivator

    接口定义: /// <summary> /// Provides methods to activate an instantiated ViewComponent /// </su ...

  5. 6行代码解决golang TCP粘包

    转自:https://studygolang.com/articles/12483 什么是TCP粘包问题以及为什么会产生TCP粘包,本文不加讨论.本文使用golang的bufio.Scanner来实现 ...

  6. CS229 6.18 CNN 的反向传导算法

    本文主要内容是 CNN 的 BP 算法,看此文章前请保证对CNN有初步认识. 网络表示 CNN相对于传统的全连接DNN来说增加了卷积层与池化层,典型的卷积神经网络中(比如LeNet-5 ),开始几层都 ...

  7. 《linux性能及调优指南》 3.3 内存瓶颈

    摘要:3.3内存瓶颈OnaLinuxsystem,manyprogramsrunatthesametime.Theseprogramssupportmultipleusers,andsomeproce ...

  8. Android图片变形,ImageView属性的设置。

    <ImageView android:id="@+id/iv" android:layout_width="match_parent" android:l ...

  9. django 解决css,js文件304导致无法加载显示问题

    这种情况一般会在windows系统下出现 1.前台.后台如果无法加载css等样式.(建议通过此办法来解决) 这是因为你安装的某些IDE 或者其他更改了注册表导致的系统的注册表\HKEY_CLASSES ...

  10. day19常用模块2

    常用模块21 shelve模块  也是一种序列化方式    使用方法        1.open     sl = shelve.open("shelvetest.txt")   ...