Graphical interfaces for pyqt and pyside Development

Source: Internet
Author: User

Copy codeThe Code is as follows:
#! /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.exe c _())

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.