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 6988609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:06:14+00:00 2026-05-27T19:06:14+00:00

In my PyGTK app, on button click I need to: Fetch some html (can

  • 0

In my PyGTK app, on button click I need to:

  1. Fetch some html (can take some time)
  2. Show it in new window

While fetching html, I want to keep GUI responsive, so I decided to do it in separate thread. I use WebKit to render html.

The problem is I get empty page in WebView when it is in separated thread.

This works:

import gtk
import webkit

webView = webkit.WebView()
webView.load_html_string('<h1>Hello Mars</h1>', 'file:///')
window = gtk.Window()
window.add(webView)
window.show_all()
gtk.mainloop()

This does not work, produces empty window:

import gtk
import webkit
import threading

def show_html():
    webView = webkit.WebView()
    webView.load_html_string('<h1>Hello Mars</h1>', 'file:///')
    window = gtk.Window()
    window.add(webView)
    window.show_all()

thread = threading.Thread(target=show_html)
thread.setDaemon(True)
thread.start()
gtk.mainloop()

Is it because webkit is not thread-safe. Is there any workaround for this?

  • 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-05-27T19:06:15+00:00Added an answer on May 27, 2026 at 7:06 pm

    According to my experience, one of the things that sometimes doesn’t work as you expect with gtk is the update of widgets in separate threads.

    To workaround this problem, you can work with the data in threads, and use glib.idle_add to schedule the update of the widget in the main thread once the data has been processed.

    The following code is an updated version of your example that works for me (the time.sleep is used to simulate the delay in getting the html in a real scenario):

    import gtk, glib
    import webkit
    import threading
    import time
    
    # Use threads                                       
    gtk.gdk.threads_init()
    
    class App(object):
        def __init__(self):
            window = gtk.Window()
            webView = webkit.WebView()
            window.add(webView)
            window.show_all()
    
            self.window = window
            self.webView = webView
    
        def run(self):
            gtk.main()
    
        def show_html(self):
            # Get your html string                     
            time.sleep(3)
            html_str = '<h1>Hello Mars</h1>'
    
            # Update widget in main thread             
            glib.idle_add(self.webView.load_html_string,
                          html_str, 'file:///')
    
    app = App()
    
    thread = threading.Thread(target=app.show_html)
    thread.start()
    
    app.run()
    gtk.main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a PyGTK app with some Buttons that, when clicked, give a
I'm cleaning up some localisation and translation settings in our PyGTK application. The app
I have created a scrolled window using pyGTK. When I type some text in
I have a string which contains svn unified diff. My PyGTK app need to
I'm trying to write a small gui app in pygtk which needs an html-rendering
In GTK (or pygtk or gtkmm...) How can I detect that an application window
I am facing the problem to need tabs in a pygtk app. Pretty much
Is there a way to not block PyGTK while performing some expensive operation? I
I wrote a simple PyGTK script to show some basic process information in a
How do I paste HTML data from the X clipboard using PyGTK/GTK+? I would

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.