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

  • Home
  • SEARCH
  • 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 6886317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:44:39+00:00 2026-05-27T05:44:39+00:00

For example: class DemoFrame(wx.Frame): def __init__(self): Initializing … self.TextA = wx.StaticText(MainPanel, id = -1,

  • 0

For example:

class DemoFrame(wx.Frame):

    def __init__(self):
        Initializing
        ...
        self.TextA = wx.StaticText(MainPanel, id = -1, label = "TextAOrWhatever")
        self.TextB = wx.StaticText(MainPanel, id = -1, label = "TextBOrWhatever")
        ...

    def StaticTextUpdating(self, ObjectName, Message):
        ObjectName.SetLabel(Message)

    def WorkerA(self):
        while True:
            Work on something

            UpdatingThread = threading.Thread(target = self.StaticTextUpdating, args = (self.TextA, "Something for TextA", ))
            UpdatingThread.start()

            time.sleep(randomSecs)

    def WorkerB(self):
        while True:
            Work on something

            UpdatingThread = threading.Thread(target = self.StaticTextUpdating, args = (self.TextB, "Something for TextB", ))
            UpdatingThread.start()

            time.sleep(randomSecs)

    ...

    def StartWorking(self):
        Spawn WorkerA thread
        Spawn WorkerB thread
        ...

As you can see, I always update StaticText in new threads, and I’m 100% sure at a whatever certain time point there’s only one thread updating a specific object, but the problem is, every now and then after running for a while, some objects just disappear. Why is this happening? Does it mean GUI updating is not thread safe? Maybe only one object can be updated at a certain time point?

Added:

OK, wx.CallAfter should be a good solution for above codes. But I got another question, what if a button event and SetLabel happens at the same time? Wouldn’t things like this cause troubles although I don’t see any?

  • 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-27T05:44:39+00:00Added an answer on May 27, 2026 at 5:44 am

    Most wx methods are not thread-safe. Use wx.CallAfter if you want to invoke a wx method from another thread; replace

    ObjectName.SetLabel(Message)
    

    with:

    wx.CallAfter(ObjectName.SetLabel, Message)
    

    Edit: Some Background Information

    In wx (And in most other UI platforms) all the UI updates get executed in a single thread called main thread (Or UI Thread). This is to make the UI work faster by avoiding the performance hit of thread synchronization.

    But the down side of this is that If we write code to update the UI from a different thread the results are undefined. Sometimes it may work, sometimes it may crash, sometimes some other thing may happen. So we should always go to UI thread to do the UI updates. So we use CallAfter function to make UI update function execute in the UI thread.

    UI thread in java

    UI thread in C#

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

Sidebar

Related Questions

A minimal example: class MainWindow(QtGui.QMainWindow): def __init__(self, parent = None): QtGui.QMainWindow.__init__(self, parent) winWidth =
I will go straight to the example: class Foo: @execonce def initialize(self): print 'Called'
For example: class Product has_many :sales_orders def total_items_deliverable self.sales_orders.each { |so| #sum the total
Consider this example: class MyClass: def func(self, name): self.name = name I know that
Example: class Author(models.Model): first_name = models.CharField() last_name = models.CharField() def _get_full_name(self): return '{0} {1}'.format(self.first_name,
Consider the following example: class A: @property def x(self): return 5 So, of course
Using for example class model(models.Model) .... def my_custom_method(self, *args, **kwargs): #do something When I
For example: class Animal def make_noise print NOISE end end class Dog < Animal
I found simple example: class Post extends LongKeyedMapper[Post] with IdPK { def getSingleton =
Look at this example: class Outer(private val handler: Actor){ def this() = this(new Handler)

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.