码迷,mamicode.com
首页 > 其他好文 > 详细

pyqt练习x3.14

时间:2014-12-14 22:34:10      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   sp   on   2014   log   bs   

import sys

from PyQt4.QtCore import *

from PyQt4.QtGui import *

from PyQt4.QtWebKit import *

 

class MyBrowser(QWidget):

 

    def __init__(self, parent = None):

        super(MyBrowser, self).__init__(parent)

        self.createLayout()

        self.createConnection()

 

    def search(self):

        address = str(self.addressBar.text())

        if address:

            if address.find(‘://‘) == -1:

                address = ‘http://‘ + address

            url = QUrl(address)

            self.webView.load(url)

 

    def createLayout(self):

        self.setWindowTitle("keakon‘s browser")

 

        self.addressBar = QLineEdit()

        self.goButton = QPushButton("&GO")

        bl = QHBoxLayout()

        bl.addWidget(self.addressBar)

        bl.addWidget(self.goButton)

 

        self.webView = QWebView()

 

        layout = QVBoxLayout()

        layout.addLayout(bl)

        layout.addWidget(self.webView)

 

        self.setLayout(layout)

 

    def createConnection(self):

        self.connect(self.addressBar, SIGNAL(‘returnPressed()‘), self.search)

        self.connect(self.addressBar, SIGNAL(‘returnPressed()‘), self.addressBar, SLOT(‘selectAll()‘))

        self.connect(self.goButton, SIGNAL(‘clicked()‘), self.search)

        self.connect(self.goButton, SIGNAL(‘clicked()‘), self.addressBar, SLOT(‘selectAll()‘))

 

 

app = QApplication(sys.argv)

 

browser = MyBrowser()

browser.show()

 

sys.exit(app.exec_())

 bubuko.com,布布扣

pyqt练习x3.14

标签:blog   http   io   ar   sp   on   2014   log   bs   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4163130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!