Sandeep Bhat wrote:
Here I am trying to code a LAN chat application.....The issue I am
facing is when I try to create an object of a wxPython Frame created
in another file. The frame is created but the buttons in it are not
properly created. So I end up getting a partial frame and the
application HANGS or freezes. The required frame has been created in
the ChatFrame file and when called in Version5 file it works well and
is successfully created but when called inside "clientCallReceiver"
creates the freeze issue.
This is because you are calling clientCallReceiver within a secondary
thread.
Message queues are associated with threads, not with windows. A window
belongs to the thread that created it, and all messages for a window get
sent to its owning thread. So, when you create your window in a
secondary thread, Windows sends the initial creation and window
management messages to that thread. However, you don't have a message
loop in that thread, so the messages are never consumed, and the window
creation hangs, unable to complete.
What you need to do is have a mechanism for sending messages back to the
main GUI thread to handle your GUI tasks. The Python Queue class works
for that, but wx.CallAfter is probably simpler. It transitions back to
the main thread. Any time you need to interact with a window, you'll
need to make sure you are in your main thread.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.