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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:56:39+00:00 2026-05-15T06:56:39+00:00

I have an interface created with Glade. It contains a DrawingArea and buttons. I

  • 0

I have an interface created with Glade. It contains a DrawingArea and buttons.

I tried to create a Thread to refresh every X time my Canva. After a few seconds, I get error messages like:

“X Window Server 0.0”, “Fatal Error IO 11”

Here is my code :

import pygtk
pygtk.require("2.0")
import gtk
import Canvas
import threading as T
import time
import Map

gtk.gdk.threads_init()

class Interface(object):
    class ThreadCanvas(T.Thread):
        """Thread to display the map"""
        def __init__(self, interface):
            T.Thread.__init__(self)
            self.interface = interface
            self.started = True
            self.start()

        def run(self):
            while self.started:
                time.sleep(2)
                self.interface.on_canvas_expose_event()

        def stop(self):
            self.started = False

    def __init__(self):
        self.interface = gtk.Builder()
        self.interface.add_from_file("interface.glade")

    #Map
    self.map = Map.Map(2,2)

        #Canva
        self.canvas = Canvas.MyCanvas(self.interface.get_object("canvas"),self.game)
        self.interface.connect_signals(self)

        #Thread Canvas
        self.render = self.ThreadCanvas(self)

    def on_btnChange_clicked(self, widget):
    #Change map
        self.map.change()

    def on_interface_destroy(self, widget):
        self.render.stop()
        self.render.join()
        self.render._Thread__stop()
        gtk.main_quit()

    def on_canvas_expose_event(self):
        st = time.time()
        self.canvas.update(self.map)
        et = time.time()
        print "Canvas refresh in : %f times" %(et-st)

    def main(self):
        gtk.main()

How can i fix these errors ?

  • 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-15T06:56:40+00:00Added an answer on May 15, 2026 at 6:56 am

    To use Python threads in PyGTK, you need to surround any access to shared GTK objects with gtk.gdk.threads_enter() and gtk.gdk.threads_leave(). See also the threads_enter() method.

    You might even be better off using GTKs functions for periodic function calls, such as timeout_add(…) and timeout_add_seconds(…) (note that recently these functions moved around a bit, and in your installation they might be in GObject and not GLib).

    Some other notes:

    1. Subclassing Thread objects is the Java way of doing things, not the Python way. The Python way is to define a function or callable object that what you need and pass it to a Thread constructor.
    2. You should not be using _Thread__stop(). It is name mangled for a reason, which is that it forms part of the internal mechanism of the Thread object and is not for normal public use. Instead, you should use one of the thread-safe objects (eg. a Condition object) and check it from the function you passed to your Thread object in step one. Alternatively, set your Thread as a daemon, so it will automatically die when the program exits.
    3. The usual extension for GTKBuilder files is “.ui”, not “.glade” (even though Glade itself appends “.glade” as the default extension.)

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A lot of JavaScript libraries have user interface widgets. Usually they are created after
I have created 4 buttons via Interface Builder. I have an array which has
I have created an interface using jQuery UI Tabs, however one of my requirements
I have created an interface with ServiceContract on interface and OperationContract on all its
I have a Tab Bar Controller created in Interface Builder Within the Tab Bar
I have a ViewController and UIWebView created in Interface Builder in it. I fill
I have created tab style interface using css and javascript with only two tabs
I have created a schema as an agreed upon interface between our company and
I have created a UISegmentedControl with two segments using the interface builder (from storyboard),
I created a UITableViewCell in Interface Builder which I have added a UIImageView and

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.