基于PyQt或PySide開發圖形化界面

nf456 9年前發布 | 67K 次閱讀 PyQt GUI開發框架

之所以選擇PyQt或PySide來開發圖形界面,主要是因為Python和Qt的跨平臺特性,Qt5甚至支持iOS和Android,并且開發相同的軟件,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(DSAPP.exec())</pre>

 本文由用戶 nf456 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!