手机
当前位置:查字典教程网 >脚本专栏 >python >pyqt和pyside开发图形化界面
pyqt和pyside开发图形化界面
摘要:复制代码代码如下:#!/usr/bin/envpythonimportsysfromPyQt4importQtGui,QtCoreimpor...

复制代码 代码如下:

#!/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_())

【pyqt和pyside开发图形化界面】相关文章:

python解析html开发库pyquery使用方法

Python 错误和异常小结

Python 开发Activex组件方法

pyside写ui界面入门示例

python实现360的字符显示界面

python 字符串格式化代码

python del()函数用法

记录Django开发心得

python 正则式 概述及常用字符

windows下wxPython开发环境安装与配置方法

精品推荐
分类导航