Tkinter - Multithreading

Поділитися
Вставка
  • Опубліковано 5 вер 2024

КОМЕНТАРІ • 49

  • @kharaktur
    @kharaktur 10 місяців тому +2

    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.

    • @jobinpy
      @jobinpy  10 місяців тому

      Thanks for your kind words!

  • @el_munoz
    @el_munoz Рік тому +1

    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.

  • @FufaTujuba
    @FufaTujuba 9 місяців тому +1

    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.

    • @jobinpy
      @jobinpy  9 місяців тому

      Thanks for watching!

  • @smittyIT
    @smittyIT 11 місяців тому +2

    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.

    • @jobinpy
      @jobinpy  11 місяців тому +1

      Thanks for watching!

  • @cristianmunoz2264
    @cristianmunoz2264 Місяць тому

    Great explanation! Thanks!

  • @georgewairobi5410
    @georgewairobi5410 8 місяців тому

    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.

    • @jobinpy
      @jobinpy  8 місяців тому

      Thanks a lot! I'm glad the tutorials are useful to you.

  • @fredflintstone8048
    @fredflintstone8048 11 місяців тому

    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.

    • @jobinpy
      @jobinpy  11 місяців тому

      Thanks for watching!

  • @johnstoddart5473
    @johnstoddart5473 Рік тому +3

    Great video, Thanks for sharing the knowledgs

  • @idopshik
    @idopshik 6 місяців тому

    So good. Your channel will be very popular.

  • @asrajan55
    @asrajan55 2 місяці тому

    Very helpful video, I have been looking for how to do this, this info is probably found nowhere else .. in a video format.

    • @jobinpy
      @jobinpy  2 місяці тому

      I'm glad you liked it!

  • @daniliser2894
    @daniliser2894 8 місяців тому

    Briliiant, well explained - well paced. thank you Jobin !

    • @daniliser2894
      @daniliser2894 8 місяців тому

      you have a new subscriber

    • @jobinpy
      @jobinpy  8 місяців тому

      Glad it was helpful!

  • @bastionjordan556
    @bastionjordan556 7 місяців тому

    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!

    • @jobinpy
      @jobinpy  7 місяців тому

      I'm glad you found the video useful. Tkinter is a great GUI toolkit and professional applications can be built using it.

  • @kychemclass5850
    @kychemclass5850 Рік тому +1

    Nice! Really useful and helpful. Thank you!!

  • @legion_prex3650
    @legion_prex3650 9 місяців тому +1

    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!

    • @jobinpy
      @jobinpy  9 місяців тому

      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!

    • @legion_prex3650
      @legion_prex3650 9 місяців тому

      @@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!

  • @ET237-ff1ry
    @ET237-ff1ry 9 місяців тому

    I love you man.. very very nice tutorials.. thanks big time..

    • @jobinpy
      @jobinpy  9 місяців тому

      Thanks for your kind words!

  • @tech-preneurshipwithjeff5745
    @tech-preneurshipwithjeff5745 Рік тому +1

    beautifully done.

  • @scotteebee
    @scotteebee 10 місяців тому

    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?

    • @jobinpy
      @jobinpy  10 місяців тому

      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.

  • @bhagyeshwargavekar891
    @bhagyeshwargavekar891 9 місяців тому

    @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.

  • @WhiteError37
    @WhiteError37 7 місяців тому

    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

  • @andromilk2634
    @andromilk2634 5 місяців тому

    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

    • @jobinpy
      @jobinpy  5 місяців тому

      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

  • @ibrahemelgammal343
    @ibrahemelgammal343 Рік тому +2

    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

    • @jobinpy
      @jobinpy  Рік тому +1

      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.

    • @mrkalvinbs1424
      @mrkalvinbs1424 Рік тому +2

      @@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

  • @MrPragmaticLee
    @MrPragmaticLee 11 місяців тому

    Is this code available for download anywhere? It would make a great starting point for a project I'm working on.

    • @jobinpy
      @jobinpy  10 місяців тому

      I don't have the code anywhere except in the video, sorry. Thanks for watching!

  • @mrkalvinbs1424
    @mrkalvinbs1424 Рік тому +1

    How would I make a button to cancel the download (cancel the secondary thread)?

    • @jobinpy
      @jobinpy  Рік тому +2

      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.

    • @mrkalvinbs1424
      @mrkalvinbs1424 Рік тому

      @@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?

    • @jobinpy
      @jobinpy  Рік тому +1

      @@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

    • @bogdansikach7709
      @bogdansikach7709 Місяць тому

      @@jobinpy Is it thread safe to use just a bool variable between threads ?

  • @SaharSahar-uh8fr
    @SaharSahar-uh8fr 5 місяців тому

  • @tech-preneurshipwithjeff5745

    what editor are you using?

  • @tech-preneurshipwithjeff5745

    what editor are you using?