pyqt和pyside開發(fā)圖形化界面
#!/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使用open函數的buffering設置文件緩沖方式
這篇文章主要介紹了Python使用open函數的buffering設置文件緩沖方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
詳解Pytorch 使用Pytorch擬合多項式(多項式回歸)
這篇文章主要介紹了詳解Pytorch 使用Pytorch擬合多項式(多項式回歸),小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05
python實現域名系統(tǒng)(DNS)正向查詢的方法
這篇文章主要介紹了python實現域名系統(tǒng)(DNS)正向查詢的方法,結合實例形式分析了Python使用socket模塊下getaddrinfo方法進行域名查詢的具體技巧,需要的朋友可以參考下2016-04-04

