pyqt和pyside开发图形化界面

yipeiwu_com5年前Python基础

复制代码 代码如下:

#!/usr/bin/env python
import sys
from PyQt4 import QtGui,QtCore
import httplib
from urllib import urlencode
import re

def out(text):
    p = re.compile(r'","')
    m = p.split(text)
    result=unicode(m[0][4:].decode('utf-8'))
    DS_Widget.setDS_TextEdit_text(result)

def dic():
    word=DS_Widget.getDS_LineEdit_text()
    text=urlencode({'text':word})
    h=httplib.HTTP('translate.google.cn')
    h.putrequest('GET', '/translate_a/t?client=t&hl=zh-CN&sl=en&tl=zh-CN&ie=UTF-8&oe=UTF-8&'+text)
    h.endheaders()
    h.getreply()
    f = h.getfile()
    lines = f.readlines()
    out(lines[0])
    f.close()

class DS_QWidget(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)

        self.DS_LineEdit = QtGui.QLineEdit(self) 
        DS_SearchButton=QtGui.QPushButton('Search',self)
        self.DS_TextEdit = QtGui.QTextEdit(self)

        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.DS_LineEdit)
        hbox.addWidget(DS_SearchButton)

        vbox = QtGui.QVBoxLayout(self)
        vbox.addLayout(hbox)
        vbox.addWidget(self.DS_TextEdit)

        self.resize(500, 300)
        self.setWindowTitle('Dictionary')
        self.connect(DS_SearchButton, QtCore.SIGNAL('clicked()'),dic)
        self.setLayout(vbox)

    def getDS_LineEdit_text(self):
        return self.DS_LineEdit.text()
    def setDS_TextEdit_text(self,text):
        self.DS_TextEdit.setText(text)

if __name__=="__main__":
    DS_APP = QtGui.QApplication(sys.argv)
    DS_Widget = DS_QWidget()
    DS_Widget.show()
    sys.exit(DS_APP.exec_())

相关文章

selenium+python实现自动登录脚本

os:windows 前提:Python,selenium,IEDriverServer.exe,ie浏览器 首先安装Python2.7 安装成功后,计算机联网状态下在cmd命令行下输入...

用python编写第一个IDA插件的实例

IDA插件是经过编译的、功能更强大的IDC脚本,与仅仅使用脚本相比,插件能够执行更加复杂的任务。与编写IDC脚本相比,python显得更为轻巧和强大,IDAPython作为IDA的一个插...

Python多线程编程(四):使用Lock互斥锁

前面已经演示了Python:使用threading模块实现多线程编程二两种方式起线程和Python:使用threading模块实现多线程编程三threading.Thread类的重要函数...

使用python实现BLAST

使用python实现BLAST

最近在自学python,又用python实现了一下BLAST。 这次更新了打分函数如下,空位罚分改为-5,但不区分gap open 和 gap extend。 ''''' @au...

python读取各种文件数据方法解析

python读取各种文件数据方法解析

python读取.txt(.log)文件 、.xml 文件 、excel文件数据,并将数据类型转换为需要的类型,添加到list中详解 1.读取文本文件数据(.txt结尾的文件)或日志文件...