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

相关文章

python绘制多个曲线的折线图

python绘制多个曲线的折线图

这篇文章利用的是matplotlib.pyplot.plot的工具来绘制折线图,这里先给出一个段代码和结果图: # -*- coding: UTF-8 -*- import nump...

详解Python中的多线程编程

详解Python中的多线程编程

一、简介        多线程编程技术可以实现代码并行性,优化处理能力,同时功能的更小划分可以使代码的可重用性更好。Pytho...

tensorflow 中对数组元素的操作方法

tensorflow 中对数组元素的操作方法

tensorflow中对tensor对象进行像numpy数组一样便捷的操作是不可能的, 至少对1.2以及之前的版本而言。 从issue上看到,有不少人希望tensorflow能及早实现这...

python实现抠图给证件照换背景源码

本文实例为大家分享了python实现抠图给证件照换背景的具体代码,供大家参考,具体内容如下 import cv2 import numpy as np import matplotl...

python+splinter自动刷新抢票功能

抢票脚本,python +splinter自动刷新抢票,可以成功抢到(依赖自己的网络环境太厉害,还有机器的好坏),但是感觉不是很完美。 有大神请指导完善一下(或者有没有别的好点的思路),...