Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:06:01+00:00 2026-06-10T16:06:01+00:00

I am trying to get a borderless python PyQt webkit window to display a

  • 0

I am trying to get a borderless python PyQt webkit window to display a single website html form. When clicking on send, the form values should be saved in a dictionnary and the window closed.

So far (with the help of a SO) I have the borderless window and can fetch the input. However, two things are missing:

  1. Closing the window after pressing send.
  2. Fetching the input in the dictionary elements (note that the keys of elements correspond to the html form names).

(potentially the other way round would be better, but 1 seems more difficult)

My code so far is:

import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

elements = {"like":"", "text": ""}

class MyWebPage(QWebPage):
    def acceptNavigationRequest(self, frame, req, nav_type):
        if nav_type == QWebPage.NavigationTypeFormSubmitted:
            text = "<br/>\n".join(["%s: %s" % pair for pair in req.url().queryItems()])
            print(text)
            return True
        else:
            return super(MyWebPage, self).acceptNavigationRequest(frame, req, nav_type)


class Window(QWidget):
    def __init__(self, html):
        super(Window, self).__init__()
        self.setWindowFlags(Qt.FramelessWindowHint)
        view = QWebView(self)
        layout = QVBoxLayout(self)
        layout.addWidget(view)
        view.setPage(MyWebPage())
        view.setHtml(html)


# setup the html form
html = """
<form action="" method="get">
Like it?
<input type="radio" name="like" value="yes"/> Yes
<input type="radio" name="like" value="no" /> No
<br/><input type="text" name="text" value="Hello" />
<input type="submit" name="submit" value="Send"/>
</form>
"""

def main():
    app = QApplication(sys.argv)

    window = Window(html)
    window.show()
    app.exec_()

if __name__ == "__main__":
    main()

A perfect answer would not only show how to (a) save the input and (b) close the window, but (c) also remove the remaining small grey border around the html page.

Update: I use Python 2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:06:03+00:00Added an answer on June 10, 2026 at 4:06 pm

    To get the form data into a dict, it is best to use unquote_plus from the python standard library as (unlike QUrl) it can handle plus-signs as well as percent-encoding.

    To close the window, you could emit a formSubmitted signal from the web-page, and connect it to a handler on the main-window. This handler could then call close() on the main-window, do all the processing of the form data, and then finally quit() the application.

    To remove the border around the page, set the contentsMargins of the main layout to zero.

    Here is revised version of your script which implements the above ideas:

    import sys
    from urllib import unquote_plus
    
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from PyQt4.QtWebKit import *
    
    class MyWebPage(QWebPage):
        formSubmitted = pyqtSignal(QUrl)
    
        def acceptNavigationRequest(self, frame, req, nav_type):
            if nav_type == QWebPage.NavigationTypeFormSubmitted:
                self.formSubmitted.emit(req.url())
            return super(MyWebPage, self).acceptNavigationRequest(frame, req, nav_type)
    
    class Window(QWidget):
        def __init__(self, html):
            super(Window, self).__init__()
            self.setWindowFlags(Qt.FramelessWindowHint)
            view = QWebView(self)
            layout = QVBoxLayout(self)
            layout.addWidget(view)
            layout.setContentsMargins(0, 0, 0, 0)
            view.setPage(MyWebPage())
            view.setHtml(html)
            view.page().formSubmitted.connect(self.handleFormSubmitted)
    
        def handleFormSubmitted(self, url):
            self.close()
            elements = {}
            for key, value in url.encodedQueryItems():
                key = unquote_plus(bytes(key)).decode('utf8')
                value = unquote_plus(bytes(value)).decode('utf8')
                elements[key] = value
            # do stuff with elements...
            for item in elements.iteritems():
                print '"%s" = "%s"' % item
            qApp.quit()
    
    # setup the html form
    html = """
    <form action="" method="get">
    Like it?
    <input type="radio" name="like" value="yes"/> Yes
    <input type="radio" name="like" value="no" /> No
    <br/><input type="text" name="text" value="" />
    <input type="submit" name="submit" value="Send"/>
    </form>
    """
    
    def main():
        app = QApplication(sys.argv)
    
        window = Window(html)
        window.show()
        app.exec_()
    
    if __name__ == "__main__":
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I am trying get the values using SP.The query is below. create proc [dbo].[GetOrdersByUserID11]
I am trying get the html within .event_recur. $(.entry).each(function(){ alert($(this).find(.event_recur).html()); }); <div class=entry> <p
Trying to get the home page to display a 4 column grid for the
I'm trying get all the button child widgets of a window. The buttons were
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Well, I'm trying get some values from places.sqlite database. But when I do $
i am very new to regular expression and trying get \ character using python
So i am trying get 2 div-containers which both should contain centered text (Both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.