Excellent tutorial, thanks to you I now have responsive tkinter apps with long running tasks. I was never able to figure this out and I just couldn't get my head around other multi-threading tutorials, but you made this subject crystal clear. You are a superb teacher.
I was trying to convert audios from video files. That means converting music videos to mp3 media files in bulk. So I have to display extracted mp3 names and total number of processed files as it goes. Your tutorials helped me achieve this goal. Thank you very much.
This video helped me immensely when writing my first multi-threaded application with customtkinter and queue. Much appreciated. I will be subscribing for future content.
Good work sir🎉. You have earned a new subscriber! I especially love the way you follow foundamental coding standards and best practices. You are teaching us to do it the write way, unlike most of the other tutorials. This is important because most of us are self taught and not CS graduates.
Maybe the application works like the video shows, but when you close the app, is very frequent that the kernel crashes, showing a message with something like "another thread try to change something in the main thread" because GUI is no thread safe. This is a very good solution to this issue, and is another good example of why the OOP approach is the best way when your application needs to do interesting things.
Another great tutorial clearly taught. Thanks for sharing. The comment at the end is so true in that most any GUI development will present this problem. The problem is the same for example with developing GUIs in Windows using things like MS Visual studio creating GUI applications. Whether using WPF, or the old Winforms approach one needs to implement threading in order to deal with this problem of long running processes freezing up the GUI and all it's controls until the process completes.
This tutorial moves Tkinter from a cute GUI tool to something incredibly useful for real world applications. I need to utilize grid geometry, so it's going to take me a bit to modify your tutorials from using the pack method to grid, so hopefully I won't go down a rabbit hole. If you have any pointers on grid geometry and threaded applications, I'd appreciate it!
How would I redirect sys.stdout and sys.stderr to another text widget in the program. Would I have to make a new class or could I use the ticket system
Great tutorial. It’s exactly what I’ve been looking for guidance on. But, if tkinter is not thread safe, what makes it safe to send the event from the child thread? Should the “after” method be used to poll the queue from the main thread instead?
Hi, thanks for watching.I've checked the tcl/tk documentation to see what makes event_generate() different from other methods in tk, as far as thread safety, and didn't find a detailed technical reason. I believe the reason for its safety is because it simulates a window event, instead of actually being from a window event. The following two links are good reads about this topic: tkdocs.com/tutorial/eventloop.html#threads and also www.tcl.tk/man/tcl/TkCmd/event.html#M7 Polling the queue using 'after' is also another workaround, but I personally prefer event_generate() without 'after' because it's worked well for me.
you have got a new subscriber! You have really nice teaching skills! But there is one thing, i don't really get. Why are you creating a new Ticket Instance for every loop? Shouldn't this be only one object with states updated? Maybe i am missing something or i don't get the purpose of the program. Otherwise, great stuff!
Hi, thanks for watching the video. I think you're right. It's possible and better to use one Ticket instance instead of creating a new object on each iteration in the for-loop; good catch!
@@jobinpy Hi! Thanks for your reply! I really like that you show advanced topics in your videos. The Queue Datatype is so good and it was a joy to see one using it! Thanks again and have a nice day!
I'm a beginner who learned a lot from this but there was one thing which I was wondering : you used auto to generate a type for the tickets in your queue, if I understand correctly, but this value what is it exactly? Is it always a string? Thanks
I use auto() for the value in an Enum when the actual value is not important in my code. I could set the value to 1,2,3,4, etc but that would take long. Using auto() takes care of this. The ticket type (name) is the only thing that's useful in this situation, so auto() allows me to forget about the value. For details, visit: docs.python.org/3/library/enum.html#enum.auto
When downloading a file with a progress bar, it's usually done using a for-loop. The for-loop needs to check for a Cancel (bool) flag on each iteration. The cancel button would simply set the cancel flag (is_canceled=True) and the for-loop would read and then see is_canceled==True and break out of the loop. Then use event_generate("",...) to notify the main thread (GUI) that the download has been cancelled.
@@jobinpy What if my thread didn't have a loop. Example: a tk program runs an automation with selenium webdriver in a secondary thread (where a log with the automation steps would be written in the tk gui [tk.Text]). Would it be possible for a 'cancel button' in the tk gui to stop this secondary thread and close the webdriver?
@@mrkalvinbs1424 Hi, I don't think there is an elegant way to close a secondary thread from the main GUI thread. However, there is a module called 'multiprocessing' and it has a terminate() method. That might be more suitable for your situation, instead of the 'threading' module. docs.python.org/3/library/multiprocessing.html
Hi, thanks for watching. I think using classes and objects makes it easier to see what's happening in the code. I'll consider the suggestion for future videos, thanks again.
Excellent tutorial, thanks to you I now have responsive tkinter apps with long running tasks. I was never able to figure this out and I just couldn't get my head around other multi-threading tutorials, but you made this subject crystal clear. You are a superb teacher.
Thanks for your kind words!
I was trying to convert audios from video files. That means converting music videos to mp3 media files in bulk. So I have to display extracted mp3 names and total number of processed files as it goes. Your tutorials helped me achieve this goal. Thank you very much.
Thanks for watching!
This video helped me immensely when writing my first multi-threaded application with customtkinter and queue. Much appreciated. I will be subscribing for future content.
Thanks for watching!
Good work sir🎉.
You have earned a new subscriber!
I especially love the way you follow foundamental coding standards and best practices. You are teaching us to do it the write way, unlike most of the other tutorials.
This is important because most of us are self taught and not CS graduates.
Thanks a lot! I'm glad the tutorials are useful to you.
Maybe the application works like the video shows, but when you close the app, is very frequent that the kernel crashes, showing a message with something like "another thread try to change something in the main thread" because GUI is no thread safe. This is a very good solution to this issue, and is another good example of why the OOP approach is the best way when your application needs to do interesting things.
Briliiant, well explained - well paced. thank you Jobin !
you have a new subscriber
Glad it was helpful!
So good. Your channel will be very popular.
Another great tutorial clearly taught. Thanks for sharing.
The comment at the end is so true in that most any GUI development will present this problem.
The problem is the same for example with developing GUIs in Windows using things like MS Visual studio creating GUI applications. Whether using WPF, or the old Winforms approach one needs to implement threading in order to deal with this problem of long running processes freezing up the GUI and all it's controls until the process completes.
Thanks for watching!
Great video, Thanks for sharing the knowledgs
Very helpful video, I have been looking for how to do this, this info is probably found nowhere else .. in a video format.
I'm glad you liked it!
Great explanation! Thanks!
This tutorial moves Tkinter from a cute GUI tool to something incredibly useful for real world applications. I need to utilize grid geometry, so it's going to take me a bit to modify your tutorials from using the pack method to grid, so hopefully I won't go down a rabbit hole. If you have any pointers on grid geometry and threaded applications, I'd appreciate it!
I'm glad you found the video useful. Tkinter is a great GUI toolkit and professional applications can be built using it.
Nice! Really useful and helpful. Thank you!!
How would I redirect sys.stdout and sys.stderr to another text widget in the program. Would I have to make a new class or could I use the ticket system
beautifully done.
Thanks!
Is this code available for download anywhere? It would make a great starting point for a project I'm working on.
I don't have the code anywhere except in the video, sorry. Thanks for watching!
Great tutorial. It’s exactly what I’ve been looking for guidance on. But, if tkinter is not thread safe, what makes it safe to send the event from the child thread? Should the “after” method be used to poll the queue from the main thread instead?
Hi, thanks for watching.I've checked the tcl/tk documentation to see what makes event_generate() different from other methods in tk, as far as thread safety, and didn't find a detailed technical reason. I believe the reason for its safety is because it simulates a window event, instead of actually being from a window event. The following two links are good reads about this topic: tkdocs.com/tutorial/eventloop.html#threads and also www.tcl.tk/man/tcl/TkCmd/event.html#M7
Polling the queue using 'after' is also another workaround, but I personally prefer event_generate() without 'after' because it's worked well for me.
you have got a new subscriber! You have really nice teaching skills! But there is one thing, i don't really get. Why are you creating a new Ticket Instance for every loop? Shouldn't this be only one object with states updated? Maybe i am missing something or i don't get the purpose of the program. Otherwise, great stuff!
Hi, thanks for watching the video. I think you're right. It's possible and better to use one Ticket instance instead of creating a new object on each iteration in the for-loop; good catch!
@@jobinpy Hi! Thanks for your reply! I really like that you show advanced topics in your videos. The Queue Datatype is so good and it was a joy to see one using it! Thanks again and have a nice day!
I love you man.. very very nice tutorials.. thanks big time..
Thanks for your kind words!
@jobinpy i am trying to create GUI using tkinter but i am facing very much GUI crashing issue. Please do video on this topic. Thanks in advance.
I'm a beginner who learned a lot from this but there was one thing which I was wondering : you used auto to generate a type for the tickets in your queue, if I understand correctly, but this value what is it exactly? Is it always a string? Thanks
I use auto() for the value in an Enum when the actual value is not important in my code. I could set the value to 1,2,3,4, etc but that would take long. Using auto() takes care of this. The ticket type (name) is the only thing that's useful in this situation, so auto() allows me to forget about the value. For details, visit: docs.python.org/3/library/enum.html#enum.auto
what editor are you using?
How would I make a button to cancel the download (cancel the secondary thread)?
When downloading a file with a progress bar, it's usually done using a for-loop. The for-loop needs to check for a Cancel (bool) flag on each iteration. The cancel button would simply set the cancel flag (is_canceled=True) and the for-loop would read and then see is_canceled==True and break out of the loop. Then use event_generate("",...) to notify the main thread (GUI) that the download has been cancelled.
@@jobinpy What if my thread didn't have a loop. Example: a tk program runs an automation with selenium webdriver in a secondary thread (where a log with the automation steps would be written in the tk gui [tk.Text]). Would it be possible for a 'cancel button' in the tk gui to stop this secondary thread and close the webdriver?
@@mrkalvinbs1424 Hi, I don't think there is an elegant way to close a secondary thread from the main GUI thread. However, there is a module called 'multiprocessing' and it has a terminate() method. That might be more suitable for your situation, instead of the 'threading' module. docs.python.org/3/library/multiprocessing.html
@@jobinpy Is it thread safe to use just a bool variable between threads ?
❤
I love u bro thank u keep the good work
but please make the code more simlpe maybe at least put OOP aside so we ca be more focused on the main method
Hi, thanks for watching. I think using classes and objects makes it easier to see what's happening in the code. I'll consider the suggestion for future videos, thanks again.
@@jobinpy Using oop despite being more complex is the correct way to work with gui. So I think you should continue the explanations using oop
Viewers: check your playback speed.
what editor are you using?
Wing Pro