My application: "starting window" with some misc. buttons etc. & server socket connection is running at the same time in a new thread.
When connection is made, the starting windows is closed and the main window will be opened.
Problem: I can't close the starting window which is Toplevel window, if I try to withdraw or destroy it, the application freeze.
I'm quite newbie so please try to answer as clearly as possible =) -
from Tkinter import *
-
import threading
-
-
master = Tk() #make the main window and hide it
-
master.minsize(width=300, height=300)
-
master.withdraw()
-
-
class first_window():
-
def __init__(self):
-
global start_window
-
-
def thread_is_finished(self):
-
main_app() #CONNECTION is made, start main application window
-
-
# start_window.withdraw() #APPLICATION HANGS IF I TRY TO HIDE THIS?!?
-
# start_window.destroy() #DESTROY DOESN'T WORK EITHER :(
-
-
start_window = Toplevel() #show the starting window
-
start_window.minsize ( width=150, height=150 )
-
start_window.bind("<<foo>>",thread_is_finished)
-
master.update() #update (bind will be "saved")
-
-
server_start().start() #start the server in a new thread
-
-
class main_app():
-
def __init__(self):
-
master.deiconify() #show the main window
-
-
class server_start ( threading.Thread ):
-
def run (self):
-
global start_window
-
#...here's the server socket code...
-
start_window.event_generate("<<foo>>") #when finished generate event
-
-
master.after_idle(first_window) #after mainloop start first_window
-
master.mainloop()
-
3 3279 bartonc 6,596
Recognized Expert Expert
Tkinter does not provide a thread-safe environment. What you are attempting is possible, but you'll need a better toolkit. These days, wxPython is what's hot (IMO). Some useful links can be found in this article.
Hope that helps...
I FOUND THE SOLUTION, damn I'm happy =D
wise man words: "Eric Brunel wrote:
> This is where the problem is: if you do just a event_generate without
> specifying the 'when' option, the binding is fired immediately in the
> current thread. To be sure that an event is created and that the thread
> switch actually happens, do: "app.event_gene rate("<<myevent 1>>", when='tail')"
so for my code: - start_window.event_generate("<<foo>>", when='tail')
and now the code is not crashing when trying to close first window
, thx Bartonc but I have about 1300lines of code (about 2weeks work) and I don't want to change GUI now =) and I like using .place for placing gui components ;-D
is wxpython more thread-safe then?
bartonc 6,596
Recognized Expert Expert
I FOUND THE SOLUTION, damn I'm happy =D
wise man words: "Eric Brunel wrote:
> This is where the problem is: if you do just a event_generate without
> specifying the 'when' option, the binding is fired immediately in the
> current thread. To be sure that an event is created and that the thread
> switch actually happens, do: "app.event_gene rate("<<myevent 1>>", when='tail')"
Thanks for that. Mr Brunel is certainly prolific. Here's the link: python mail list
so for my code: - start_window.event_generate("<<foo>>", when='tail')
and now the code is not crashing when trying to close first window
, thx Bartonc but I have about 1300lines of code (about 2weeks work) and I don't want to change GUI now =) and I like using .place for placing gui components ;-D
is wxpython more thread-safe then?
I'm impressed that Tkinter is working in this manner. wxPython is a complete toolkit for working on (w)indows and (x) platforms, including threads and processes.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Charles Starrett |
last post by:
I am a just a dabbler in programming, but I'd like to make some simple
cross-platform tools for generating webpages, as well as for text
munging. One thing I need is a Mac OS 9/Windows GUI solution. I
thought that Tkinter could provide this, but I'm having trouble
getting the simple test script from Learning Python p.22 to work under
Mac OS 9 (9.2.2, on a 400 MHz PowerBook firewire/2000, 192 MB ram).
Starting with a clean install of...
|
by: Michael Schutte |
last post by:
I know, questions about Tkinter and threads have been answered very
often, but I want to ask anyway.
I am using Python 2.2 on a Linux (SuSE Linux 8.1) system.
I want to write a server application; like telnet is a client. The user
should be able to bind() to a port and wait for a client. The written
and recieved data is stored in a Text widget, self.__text. The
accept()ing is done in a seperate thread (using the threading module),
in...
|
by: george.trojan |
last post by:
My application consists of Tkinter GUI that has to communicate with a
remote
server. The communication is bi-directional: the GUI responds to remote
requests and user actions uch as pressing a button) should send messages
to the server. I want to have the network interface implemented as a
separate
thread, as it may take a while to proccess incoming messages. My initial
approach is the following
|
by: corrado |
last post by:
Hello
I have an application running several thread to display some financial
data;
basically I have a thread displaying HTML tables by means of Tkhtml,
another implementing a scrolling ticker based on a Text widget with
embedded windows and a thread running the Tkinter mainloop plus
several other thread dealing with the scheduling of the contents and
the acquisition of data but not using graphic widgets.
I run the same code on Linux...
|
by: RahimAsif |
last post by:
Hi guys,
I would like some advice on thread programming using C#.
I am writing an application that communicates with a panel over
ethernet, collects data and writes it to a file. The way the data is
collected is that we have different schedules (so one set of data is
collected say every second, another set of data might be collected
every 30 seconds, and so on).
| |
by: Tuvas |
last post by:
I am building a tkinter program. A part of this program is to read data
from an incoming interface, and depending on the data, will display a
bit of text on the tk dialog, it decodes this data, so to speak. If one
command is sent, everything's just fine. When multiple are sent, the
program will stop responding, and will only continue to respond after
one types <ctrl>-c. The statement at fault is something like this.
e1=StringVar()
Label...
|
by: Hendrik van Rooyen |
last post by:
Hi,
I get the following:
hvr@LINUXBOXMicrocorp:~/Controller/libpython display.py
UpdateStringProc should not be invoked for type font
Aborted
and I am back at the bash prompt - this is most frustrating, as there is no
friendly traceback to help me guess where its coming from.
|
by: Kevin Walzer |
last post by:
I'm trying to decide whether I need threads in my Tkinter application or
not. My app is a front end to a command-line tool; it feeds commands to
the command-line program, then reads its output and displays it in a
Tkinter text widget. Some of the commands are long-running and/or return
thousands of lines of output.
I initially thought I needed to use threading, because the GUI would
block when reading the output, even when I configured...
|
by: Dudeja, Rajat |
last post by:
Hi,
So, now I've finally started using Eclipse and PyDev as an IDE for my
GUI Application. I just wrote some sample programs as an hands on.
Now I would like to take up Tkinter. I'm using Active State Python
version 2.5 and found that there is not Tkinter and Tk module in it.
To use Tkinter do I actually require Tk installed on my machine? Please
suggest and where can I find both these modules?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |