pyqt和pyside开发图形化界面
2019/7/13 21:57:03
本文主要是介绍pyqt和pyside开发图形化界面,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#!/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开发图形化界面的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-03用FastAPI掌握Python异步IO:轻松实现高并发网络请求处理
- 2025-01-02封装学习:Python面向对象编程基础教程
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型