pyqt和pyside开发图形化界面
时间:2022-05-06 18:10:08
#!/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_())
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python使用ntplib库同步校准当地时间的方法
Python cookbook(数据结构与算法)从序列中移除重复项且保持元素间顺序不变的方法
php根据isbn书号查询amazon网站上的图书信息的示例
用ASP实现txt,doc,jpg等文件下载的函数
使用XSLT将XML数据转换成HTML
如何基于python实现脚本加密
![](https://img.aspxhome.com/file/2023/8/99308_0s.png)
微信公众平台网页授权获取用户基本信息中授权回调域名设置的变动
![](https://img.aspxhome.com/file/2023/3/88293_0s.jpg)
一些建站常用简单html代码
Django渲染Markdown文章目录的方法示例
![](https://img.aspxhome.com/file/2023/9/81569_0s.jpg)
AJAX概述
Python之列表的append()方法最容易踩的坑
Python SMTP发送电子邮件的示例
Python计算点到直线距离、直线间交点夹角
![](https://img.aspxhome.com/file/2023/2/87982_0s.jpg)
Tensor 和 NumPy 相互转换的实现
互联网产品交互事件分析
利用Anaconda完美解决Python 2与python 3的共存问题
Python如何使用字符打印照片
![](https://img.aspxhome.com/file/2023/1/67241_0s.jpg)
python中的迭代和可迭代对象代码示例
BOF、EOF 属性
pycharm2022没有manage repositories配置镜像源的解决方法
![](https://img.aspxhome.com/file/2023/9/78449_0s.png)