▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My KZbin Channel: bit.ly/2UFLKgj bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN ▶️ Get The Code bit.ly/3fLFQ8p
@codewithahmed98064 жыл бұрын
Nice Video
@Planet_Xplorer3 жыл бұрын
Greetings from your Egyptian fans! I think it will be a good idea if you post the code of the video somewhere so that people can easily try it for themselves. Thanks ☺️
@Codemycom3 жыл бұрын
@@Planet_Xplorer Of course I do that. The link is in the pinned comment under each video. The pinned comment you just posted under lol
@Planet_Xplorer3 жыл бұрын
@@Codemycom My bad! lol Thanks dude and keep the good work!
@peterpacsay83583 жыл бұрын
You have great tutorials! In my humble opinion If you do not want to start 5 second counting automatically I think you need: my_button1 = Button(root,text = '5 seconds',command= lambda: threading.Thread(target=five_seconds).start()).
@jordanstein8923 жыл бұрын
I can't tell you how much I appreciate this... I went to the comment section specifically to find someone talking about this.
@peterpacsay83583 жыл бұрын
@@jordanstein892 You can find another solution in the the next video: Tutorial#98
@emanuelojea64122 жыл бұрын
@@jordanstein892 totally agree!!! thx so much @Peter Pacsay
@adrianojose71722 жыл бұрын
@@jordanstein892 hi there, can you please tell me why y'all want to use lambda? I'm new to this so. Thank you
@linasmariusnasvytis76002 жыл бұрын
Legend!
@holycow48893 жыл бұрын
Man, i literally find everything i'm looking for on your channel, thank your very much for this video.
@Codemycom3 жыл бұрын
hey awesome!
@evanlavizadeh40323 жыл бұрын
I think it's better to use command=(threading.Thread(target=five_seconds).start) instead of command=(threading.Thread(target=five_seconds).start()) because the latter will run five_seconds in this very line while the former will not. Most cases, you don't want the command to start until the button is pressed. edit: Also this doesn't work when you try to press the "Wait 5 sec" button twice. You will get: RuntimeError: threads can only be started once. It feels almost as though you hid that fact by only demoing the functionality by closing and re-starting the program instead of clicking the button multiple times? Feels like an unfinished tutorial.
@rockmero3733 жыл бұрын
I was stuck with this issue. You saved me. Thanks!
@evanlavizadeh40323 жыл бұрын
@@rockmero373 you're welcome! I was stuck with it too haha
@abhinavs48752 жыл бұрын
yeaa soo do you know how to make my button function continuously without getting the runtime error??
@ashyy63052 жыл бұрын
You're the best, I've been stuck with this issue for days D:
@evanlavizadeh40322 жыл бұрын
@@abhinavs4875 I did fix it but it was too long ago to remember sorry.
@danilodelucio3 жыл бұрын
You are amazing, man, thank you so much! If someone is having a problem where the function "start" starts before, just put the lambda before threading. This is my situation: enter_button = Button(frameRadio, text="ENTER", bd=0, bg="#005C7A", fg="white", font=(font_type, 10, "normal"), command=lambda: threading.Thread(target=enterButton).start())
@Codemycom3 жыл бұрын
Thanks!
@Planet_Xplorer3 жыл бұрын
That's a life saver dude!! Thanks for the suggestion :-)
@dataclips3 жыл бұрын
Thanks Danilo!
@mikewyrick87153 жыл бұрын
wish I would have read this sooner! lol
@joelmanning2493 жыл бұрын
Don't know if you encountered this rather peculiar feature but: When wrapping my button event to my thread I noticed that: target=("function").start() will cause the event to run on the start up on the program However if I change it to the following: target=("function").start then the event will now run on the button click
@selimahmedov85913 жыл бұрын
Had the same issue - on start-up the function would start running without pressing the button. Removing the () from start solved the issue. Thanks a lot.
@VascoCC953 жыл бұрын
He himself explains that on one of the first episodes of this series... 😅
@nicolaspoyet35482 жыл бұрын
Thanks !
@raoulalfonze21923 жыл бұрын
Incredibly easy way to get this done! I've been looking for a way to get a tkinter GUI to stop freezing on long tasks, and this does it perfectly! Thank you!
@parthchopra3152 жыл бұрын
did it worked dude? coz my GUI crashes after every 2-3 hours running extrnsively. HELP BROOO
@frankrogowski9595 Жыл бұрын
Wow this is excellent! I am developing a FinTech payment processing application and I am at the point where threading is very necessary. So simple. Great teacher-instructor. Thank you! Going to to apply this to my notebook/tabs where my application is split out logically and may hang the rest of the program if a single threaded. Love these series of Tkinter. Wish I would have found these a 1yr ago. I am now a Tkinter junkie.
@Codemycom Жыл бұрын
Awesome, happy to hear it!
@eddw1232 жыл бұрын
I think he didn’t notice ! the 5 seconds button was automatically pressed by the >> .start() >>command=lambda: threading.Thread(target=five_seconds).start())
@fernandocorenstein65313 жыл бұрын
Best channel for python on KZbin. Why aren’t people subscribing to this lovely channel?
@Codemycom3 жыл бұрын
tell your friends ;-)
@darshanpanchal30464 жыл бұрын
You are great sir....you are awesome........thank you thank you so much......i was just stuck there for about 2 weeks.....love you sir.......
@Codemycom4 жыл бұрын
Thanks!
@RyanDanielG3 жыл бұрын
LOL the last few days i have been writing a program with a while loop in it and it caused me ALL KINDS of problems. In the end i restructured the entire thing so I didn't need the loop... I was only 3 vids away from this video in the playlist ;| Wish I had watched this first. Woulda saved me about 12 hours. Google sent me to StackO the posts I saw mentioning threading mostly said 'dont do it, its complicated, work around it'. Great tool and now I understand it. Thanks!!
@Codemycom3 жыл бұрын
Ha, awesome
@andrejvujic4 жыл бұрын
That iconic: and we'll give this a pady of 20 just to push it down a little
@Codemycom4 жыл бұрын
ha!
@64bitMario2 ай бұрын
Great guide! Now I'll never forget to give a widget pady=20 to push it down a little bit.
@Codemycom2 ай бұрын
ha! nice
@captainmacro59042 жыл бұрын
The best video about treading i ever seen
@Codemycom2 жыл бұрын
Happy to hear it!
@insertx2k_dev2 жыл бұрын
Thank you for your time to help us small developers improve our software, you are a real hero.
@Codemycom2 жыл бұрын
Thanks :-)
@mustafaaldulaimi98043 жыл бұрын
the only youtuber who is really knowing what he is doing thank you so much
@nebular-nerd Жыл бұрын
A super simple explanation that works, top stuff!
@Codemycom Жыл бұрын
Thanks!
@bobzarrabi00244 жыл бұрын
Great videos. Thank you. I just replicated your code but in my case, the function starts automatically before I click the Button. what am I missing !! start = Button(frame, text="Start", command=threading.Thread(target=m.main).start())
@bobzarrabi00244 жыл бұрын
Actually I found the answer, just going to post it if anyone else encounters the same issue: stackoverflow.com/questions/49085244/tkinter-button-command-getting-executed-before-clicking-the-button
@Codemycom4 жыл бұрын
yep
@simonebollati52854 жыл бұрын
@@bobzarrabi0024 Thx man !!!
@samdan874 жыл бұрын
@@bobzarrabi0024 THANK YOU
@danilodelucio3 жыл бұрын
Thank you so much!
@ruioliveira41494 жыл бұрын
You don´t know how much you saved my life with this. Thank you 100000000 times, really really thanks :)
@Codemycom4 жыл бұрын
Glad it helped you!
@uninho19854 жыл бұрын
Omg I was searching so many forums for this solution.... thanks thank thanks
@Codemycom4 жыл бұрын
Glad I could help!
@uninho19854 жыл бұрын
@@Codemycom I have one question please. I created a tool that uses selenium for web automation. I have created threads for each button that calls a function (long running loops). I have e. g. a Start and a Pause button. The pause button should break the loop. To get this, I have created a bol (start_process = True/False). Pressing Pause button will change start_process to False and then the tool stops the loop. All good so far, that works great. But the threads keep running background once stared and that leads to an error, because selenium tries to find a button which is currently not available after I pressed Pause. Basically, you can imagine like that, when I start the process, my tool will keep clicking and waiting for some XPATH's. When I press pause, the tool will jump put of the mask and switch to another window. So Selenium of course cant find the XPATHs anymore.>> error. Is there a way, that I can like terminate the main thread after I pressed pause? I know there is this "daemon" thing, but cant get it running since I dont know where and how to implement it. Would be great if you would have a solution for my problem on hand. I love you videos! I really learned a lot as a hobby newbie coder ;-)
@DanielSilva-fv8br4 жыл бұрын
@@uninho1985 I have a similar problem. Did you find out how to kill the thread?
@uninho19854 жыл бұрын
@@DanielSilva-fv8br Yes, I have tried a round and found that creating a thread for each button that calls a function was the key. Then I have created booleans like bol_start = True which gets changed to bol_start = False after pressing the pause button. It will finish the loop that was started already, and stops after that. In my personal case, since I did not want to wait for the loop to get finished, I also created an "idle" function that interrupts the running loop by clicking on a different navigation button on the web app.
@michaeltennyson75643 жыл бұрын
your videos and website have helped me learn so much. thanks john!
@Codemycom3 жыл бұрын
Very happy to hear it!
@myatthurawin22764 жыл бұрын
Very Thanks. I have been searching for the whole night!!!!!
@Codemycom4 жыл бұрын
Very cool!
@elielberra28672 жыл бұрын
Thank you very much for all the tutorials on Tkinter you have provided, they were very useful!!
@Codemycom2 жыл бұрын
Very welcome!
@roni52453 жыл бұрын
Hi! I have a question. I'm making a game using the turtle module which I know was created with tkinter. I'm trying to use a thread in order to be able to do two things simultaneously. But, I'm getting the following error: RuntimeError: main thread is not in main loop. Do you know how to fix this by any chance?
@100percentTrading2 жыл бұрын
Awesome. This is exactly what I was searching for. You've saved my day.
@Codemycom2 жыл бұрын
Happy to hear it!
@RyanDanielG3 жыл бұрын
Smash that like button guys n gals! its free! great python tkinter tutorial, Codemy. Thanks
@u2gilles2 жыл бұрын
This technique works only if TKinter is thread-safe as you modify a label in the second thread. Can you confirm that it is ? because I read conflicting information about it.
@tamasvida6454 Жыл бұрын
many thanks dude FINALLY i was able to fix my code after 2 month of trying D:
@Codemycom Жыл бұрын
Happy to hear it!
@tpz14744 жыл бұрын
very nice tutorial, easy to follow, direct & to the point! thank you very much for this.
@Codemycom4 жыл бұрын
Glad it was helpful!
@aldopereira36494 жыл бұрын
when I start my tkinter program all functions are activated with this metod :C Help
@aldopereira36494 жыл бұрын
command=lambda:threading.Thread(target=five_seconds).start() #add lambda before to threading to all function
@PolosPhotography4 жыл бұрын
THANKS
@rodrigoportillo27474 жыл бұрын
Thank you worked for me!
@mvpetrone3 жыл бұрын
ratio'd lol
@nero_ap60933 жыл бұрын
@@aldopereira3649 Thank you very much! 💜
@SaxeZz14 жыл бұрын
Hello, i have a question. Do you know, by any chance, a way to stop/kill/terminate a Thread just created in the command variant? I want to start a calculation by button but also want to be able to terminate the calculation while the calculation. Unfortunately, i also can not restart it as you do in the video. For example, the Thread is done and I click "start" again it won't start and says RuntimeError: threads can only be started once. Does anyone know what to do?
@amritsingh9784 жыл бұрын
bro he dont expalined it wisely ,i am very dissapointed . you can use multiprocessing instead
@venkatvenky00794 жыл бұрын
Same problem here. If someone know, pls explain the solution
@myatthurawin22764 жыл бұрын
same problem here please tell me if you find solution
@myatthurawin22764 жыл бұрын
@@venkatvenky0079 same problem here please tell me if you find solution
@venkatvenky00794 жыл бұрын
@@myatthurawin2276 use lamda command in button command. It helps for me
@sammorganmoore2 жыл бұрын
great video, I want something running on a thread that just autostarts is not activated by a button (example flashing button red 5s, blue 5seconds) that starts flashing when the window is opened and continues flashing while one does other stuff?
@rehmankhan-ve9vo3 жыл бұрын
Thanks a lot sir , You have saved my time . I was searching for this solution and you solved this . Thanks a lot ❤️❤️❤️❤️❤️
@Codemycom3 жыл бұрын
Glad you liked it!
@rgsoussama4 жыл бұрын
Thanks you ! that helps a lot But idk why the function starts when i run my program (i don't even click on the button), and the button won't do anything when i press it after that
@rgsoussama4 жыл бұрын
Solution: threading.Thread(target=myfunc).start instead of command=threading.Thread(target=myfunc).start() .
@Codemycom4 жыл бұрын
Interesting!
@ntrasla4 жыл бұрын
@@rgsoussama thanks
@lloydthomas89624 жыл бұрын
this worked for me too, maybe its a python 2.7 thing? welcome to the stone age!!
@venkatvenky00794 жыл бұрын
I used command=threading.Thread(target=function).start But once i click the button it works.after the run finished,, if i click the same button it is not doing anything. Im using python 2.7.
@elysonpanolino75222 жыл бұрын
My screen is now broken because I smashed the like button
@Codemycom2 жыл бұрын
Awesome!
@shanril3 жыл бұрын
How to effectively use multiprocessing with Tkinter?
@leomena76793 жыл бұрын
my thread is somehow starting by itself, Once ir runs the first time (right after its drawiing) it will not execute again, regardless of whether you click the button.. Any thoughts why?
@Codemycom3 жыл бұрын
Not sure...it seems you've done something wrong...
@Victor_Marius3 жыл бұрын
@@Codemycom the example is wrong. When passing the command argument the thread is stated because it is calling the .start() method. You either omit the () to pass in the .start method and not the return of .start(), or you use lambda function, command = lambda: threading.Thread(target=...)
@НиколайТест-у8ф4 жыл бұрын
would be cool if you could show how to handle the thread running, especially how to stop it again.
@julicojotase2 жыл бұрын
Thank you so much i had a headache with opencv, trying to get still the camera frame
@Dhruv_Jadhav4 жыл бұрын
I was reading about threading and came across the Queuing module. This module was used in a lot of answers in Stack Overflow. Could you also make a video about queuing events in Tkinter. Thanks!
@Codemycom4 жыл бұрын
we'll see
@hussamcheema3 жыл бұрын
@@Codemycom yes man, please make a video on queuing module.
@xreed810 ай бұрын
You could definitely use time.sleep() in a pyqt/tkinter/etc program. For example, typically web scraping projects will, at some point no matter what you do, require you to use time.sleep() in order to accommodate unexpected connection issues, HTML DOM lag, network lag, etc.
@Codemycom10 ай бұрын
Sure...but this is not a pyqt video...?
@xreed810 ай бұрын
@@Codemycom Meant for General GUI frameworks. Edited my comment😆
@chr_isso3 жыл бұрын
Why are there so many complaints on the net that the mainloop freezes? I can't adapt this simple piece of code because my mainloop freezes aswell. I can't do a single thing once I start my thread. I think tkinter is a mess ... *frustrated*
@DanielSilva-fv8br4 жыл бұрын
Hello, can someone tell me how to kill a thread? I'm using thread for a function with a while loop and it works but i don't know how to kill the thread when i close the program.
@michaelfuchsluger63433 жыл бұрын
I think Threads are unkillable. They end when they end. You have to kill the process where the thread is running in.
@richardspahn13203 жыл бұрын
This question has been asked several times. Let's encourage John @Codemy to PLEASE do a follow up video addressing how to kill a thread.
@BrendonWilliams4 жыл бұрын
This code is bugged. command=threading.Thread(target=five_seconds).start() needs to be command=threading.Thread(target=five_seconds).start or command=lambda: threading.Thread(target=five_seconds).start(). With how it is now, you're starting the thread when the button is created, not when it's clicked. Also, creating a thread on every button click isn't ideal. A thread pool would be a better alternative to allow reuse of threads.
@ramonschmeitz514 жыл бұрын
ty so much my program wasn't working because of this
@BrendonWilliams4 жыл бұрын
@@ramonschmeitz51 No problem. I know about it because a user on Stack Overflow had a problem as well (likely the same problem as you).
@savinseneviratne32662 жыл бұрын
sir, if i may ask, lets say that there is a button in tkinter that run a threaded function, and once the function is over, i want to press the button again and re run the same function without freezing the gui. how can i do that?...
@yuemeng85572 жыл бұрын
你好Hello!Thank you so much for the video tutorial. I wrote a while loop in the thread to refresh the control.I want to use another button to terminate the thread or exit the thread.What should I do?
@benjimanguapo4 жыл бұрын
Wow that is super cool, I love your videos. Like from México.
@Codemycom4 жыл бұрын
Thanks!
@maksimantonio47324 жыл бұрын
Great tutorial ! One question: are you sure its thread safety, i mean if you put lots widget configure in thread function, will it still lead to main window stuck ?
@icodeint27803 жыл бұрын
am getting an error that i can't get fixed, threading as no attribute 'Thread' due to circular import,
@leedaluyo3 жыл бұрын
same here
@icodeint27803 жыл бұрын
Well fix it, make sure you have no variable name threading or anything similar, no a .py named threading.
@Dhruv_Jadhav4 жыл бұрын
Good job on the video! I have a question though. So I started a thread to take care of a function that was freezing my program like crazy. So the function starts when I press a button but that particular function starts before I click on the button. Is this an error or what should I do to fix it? Thanks!
@Codemycom4 жыл бұрын
Why does the function start before you click the button? You should set up your threading to start when the function starts....
@Dhruv_Jadhav4 жыл бұрын
Lemme check my code
@Codemycom4 жыл бұрын
@@rgsoussama try leaving off the () from .start()
@Dhruv_Jadhav4 жыл бұрын
@@Codemycom It worked!!! Thanks.
@Codemycom4 жыл бұрын
@@Dhruv_Jadhav Glad to hear it!
@jaipreetsingh304 Жыл бұрын
Thank you for this video, but what if I want to send parameters like root(which is tkinter object) into five_seconds(root). Will it behave the same, I tried to do so but it is not running together. I tried args but it is not able to send root object to other function. Kindly Help
@mobinwb2 жыл бұрын
I wanted to run FuncAnimation along with another function in a thread. but cant pull off. Stackoverflow couldnt solve it. Any idea, how can I do this?
@BWNL_BILL Жыл бұрын
i am getting a problem with my code whenever i run my code it will immediately run the thread freezing my code until its done waiting
@jokarjapan2 жыл бұрын
This is what i'm looking for, thank you
@Codemycom2 жыл бұрын
to hear it!
@jokarjapan2 жыл бұрын
Hhhhhhhhhh nice return (^_^)
@filipemarques40912 жыл бұрын
How can i use threading to mix song 1 and song 2, decreasing the volume of song 1 in the end and increasing the volume of song 2 in the begining?
@ztech3401 Жыл бұрын
hey can you solve this problem please RuntimeError: There is no current event loop in thread 'Thread-1'.
@abhinavmane603 жыл бұрын
I have a big code fucntion with some loops in it so my tkinter window just hangs for a bit is there a different approach for this problem please respond it will be very helpful of you to respond.
@jugen1231232 жыл бұрын
How could I restart or stop the origninal threading while I click the "5 seconds" button again ?
@haxzor253 жыл бұрын
Thank you soo much i was searching the exact fix.
@Codemycom3 жыл бұрын
glad it helped
@elentu12693 жыл бұрын
Can be used asyncIO (asynchronous programming) to solve the freezing?
@MrRagishtin3 жыл бұрын
you're great man .. I really can't thank you enough ..
@Codemycom3 жыл бұрын
Glad to help
@alexvillegas8155 Жыл бұрын
You are a genius ! Thank you so much !
@Codemycom Жыл бұрын
Welcome
@neonsloth3 жыл бұрын
For me, any command I put into a button runs immediately as soon as TK opens. I used a lambda function in order to fix that. But now even the new thread freezes TK.
@tobi54653 жыл бұрын
how to stop the thread? and how to stop correctly, when the window is just closed?
@richardspahn13203 жыл бұрын
Exactly. For example, if you click on the [X] button in the top-right of the window to close the window after the "5 Seconds" button has been clicked and before it completes, an exception error is raised( Exception in thread Thread-1) because the thread is still running. Can you PLEASE do a follow up video on how to kill a thread?
@gajendrasonare3 жыл бұрын
I used threading for Tkinter but the problem is matplotlib is thread incompatible. What should I use now instead of threads so that I can work with matplotlib without freezing the GUI?
@spugged98003 жыл бұрын
I needed this so bad, I was making a game timer for when the mobs respawn and this was killing me!
@furkank56144 жыл бұрын
Hi nice video, i am working on a Voice Asisstant code. When i click the button command it's Get Audio. I tried apat this "thread" to my program but when i run it it, gets the audio before anything appears. After that Tkinter appears when i click the button it does nothing. I wish you can help.
@jeremyayers39774 жыл бұрын
When I switch my function to run as a thread, my tkinter input fields aren't recognized. I'm trying to myEntry.get() from within the threaded function and I get an error saying myEntry is not defined. If I run my code without threading it works fine.
@Codemycom4 жыл бұрын
Hm...weird
@lamnguyentrong2753 жыл бұрын
does the thread end after the function has finished. ? normally i see some people has to use threading.join() to finish.
@adrisdrsglt61644 жыл бұрын
Okay guys if you have a problem when using start() and in the next video he said that you can remove the "()" and just type func.start and it is supposed to work but it still doesn't than check if your function involves global variables
@elmerv19343 жыл бұрын
en mi caso sin necesidad de apretar el botón se ejecutaba el bucle five_seconds(), y al quitar los paréntesis todo funciona normal pero solo puedo ejecutarlo solo una vez sino la consola me vota error
@screensauce3 жыл бұрын
Amazing video love it. Made it really clear but Can you use this to thread a while true loop that's is blocking the root. mainloop() pls reply
@pengxiangyu73914 жыл бұрын
Great Video! I just have a question though, it seems we can only press the button once. It will cause 'RuntimeError: threads can only be started once' if pressing the second time. Any idea on how to solve that?
@Codemycom4 жыл бұрын
Disable the button till after the thread finishes then enable the button again
@chukk4 жыл бұрын
Codemy.com Hi, I’m in the same situation of needing to use a button/thread multiple times. How do you go about doing what you suggested?
@chukk4 жыл бұрын
I found an answer in subclassing threads. Including this in the video would be super helpful. I’m surprised it’s not talked about more.
@xinpengdu38154 жыл бұрын
I had exactly the same issue. Here is the solution: don't open a thread in the command. just use the command in the original way, such as command=func. Then in func, define a sub-function. Put your original code in the sub-function, and use the func to open and start a thread. Something like this: def func(): def sub_func(): Your code threading.Thread(target=sub_func).start() button_1 = Button(root, text="YourText", command=func) button_1.pack()
@andresdeinnocentiis64983 жыл бұрын
@@xinpengdu3815 Statues should be made in your name
@flydr22 жыл бұрын
Many thanks.... very well explained
@Codemycom2 жыл бұрын
Happy to help!
@wyattmurphy62174 жыл бұрын
These videos are so helpful!!! I'm working on a project now where I think threading could be used. I was wondering: If two separate threads were created which called the same function, that had a variable; would each thread iteration change the variable def for each other or would the variable changes be contained to each thread? (i.e. thread A changes x to 1 and thread B changes x to 2. Would thread A, now read an x value of 2 on its next iteration?!)
@Codemycom4 жыл бұрын
Try it and see :-P It depends on how you write the code
@premgarg55344 жыл бұрын
What type of project you are working on? I am sure i can help you there
@Planet_Xplorer3 жыл бұрын
I got it working...but what if you want to pass the number of seconds as a parameter to the five_seconds def so that you could choose the number of seconds? I tried a small edit like five_seconds (5) but once the form opens shows ""5 Seconds Is Up!" even thought I didn't click the button...any thoughts about that? thanks
@merijns34463 жыл бұрын
You can can use lambda for this, the code would look like: command= lambda: threading.Thread(target= five seconds, args=[amountOfSeconds]).start
@Planet_Xplorer3 жыл бұрын
@@merijns3446 great, thanks!
@merijns34463 жыл бұрын
@@Planet_Xplorer no problem, happy to help!
@kingsleyjide44869 ай бұрын
what about for multiprocessing, why does it create new instances of the app
@benitez9rh4 жыл бұрын
even with threading, I have a function that is taking a lot longer in tkinter than it does just running a python script off of Spyder. Any idea why that is?
@ncclasses74713 жыл бұрын
I am trying this for a button having function which is using lambda and entry both... And when I use threading for this it doesn't work
@step_freeskills1012 жыл бұрын
Hi John as always nice video...by the way got a question, what is the difference between threading and after method?
@alirezarezaie61483 жыл бұрын
nice really awsome but how to stop thread?
@shlokshah35223 жыл бұрын
Hi great video, how could I run a function with threading that allows arguments to be passed into that function
@Codemycom3 жыл бұрын
use a lambda in the normal way
@ravindrakarale76783 жыл бұрын
Thank you so much for this i was looking for that only
@Codemycom3 жыл бұрын
Glad I could help
@mememachine30202 жыл бұрын
This tutorial was very helpful!, though im not so sure on how to stop a thread
@joedavies69182 жыл бұрын
Did you ever figure this out with tkinter? I'm currently stuck on the same thing!
@martincastello98664 жыл бұрын
Hi! i could not be able to use threads in a gui structured in a class as the documentation recomended, can you give me some leads? the error is this: RuntimeError: main thread is not in main loop. Thanks for the answer!
@johnbonhomme22324 жыл бұрын
I am having the same problem, but I may have found a solution (I haven't had the chance to try it yet). Check out tkthread
@-eckes-w.35743 жыл бұрын
very cool, but one question: you wrote --- my_label2.config(text = ƒ"Zufallszahl : {randint(1, 100)}") --- but this won't run on my machine, so i change it to --- my_label2.config(text = f"Zufallszahl : {randint(1, 100)}") ---- and it works. Seems to be the same, but the differece is the "ƒ" and "f". I don't know how to make this function-sign - i copieed from google search. The normal f runs.
@Codemycom3 жыл бұрын
Use a normal f...I have no idea what that other thing is or why you're using it.
@Planet_Xplorer3 жыл бұрын
My program takes few minutes when I press the ok button...I've applied the threating but the form still freezes...is there any 'threading' setting that could solve the problem?
@Codemycom3 жыл бұрын
No, you likely just didn't set up the threading correctly
@Planet_Xplorer3 жыл бұрын
@@Codemycom ok thanks
@MoltiSanti4 жыл бұрын
Oddly this didn't work for me until I appended "lambda:" to the line. So, command=lambda:threading.Thread(target=find).start()
@Codemycom4 жыл бұрын
Interesting!
@andreamarchisio96083 жыл бұрын
When launching the program the target function of the program gets executed once even though I do not click on the button..Why is that? Also, how do create a window from a thread without getting "main thread is not in main loop" error? Thanks
@andreamarchisio96083 жыл бұрын
found the answer to the first question in this comment section..Please still consider my second question :)
@harshdeepsingh45784 жыл бұрын
Hi, I used threading with Tkinter and it worked great but I faced a problem when I had to get a return from the function being called. for example, def test(): return 5 I want to be able to use and store that value and I have not been able to. part 2: I am also displaying live data using matplotlib.animation, this also freezes my app. However, when I use threading the live graphs I display disappear. Noth sure why this is. Could you give some advice?
@michaelfuchsluger63433 жыл бұрын
I think I have a similar problem: I made a simple game and I want to run the GUI-update on a different thread than the game mechanics in order to speed up the game. But for some reason, when I start a new thread, it says "error: main thread is not in main loop". import turtle import threading wn = turtle.Screen()... ... def window_updating(): while True: wn.update() threading.Thread(target=window_updating).start() Without a new thread it works fine but if I start a new one, I get the error I mentioned before. My objects don't get updated on the screen, but the game mechanics are stil running. Maybe someone could help me too with this problem.
@krishnanandshenoy28414 жыл бұрын
Thank you for the video🙏 ..... Is there a limit to creating threads?
@kyleyoung49744 жыл бұрын
yes it is based on the processor chip in your computer
@Player-ix7rx4 жыл бұрын
Great video, one question tho, I created a tkinter gui with quite a lot of functions inside of it that checks some live data (it grabs around 30-40 live data, each one with its own function and some math inside...), I use the '.after(1000)' function for the refresh, but after a while will freeze, should I use threading for each function? Thanks!
@Codemycom4 жыл бұрын
Without seeing your code, I couldn't say. But try it and see.
@modelrailwaytheeasyway97434 жыл бұрын
Hi John another great video and just what i needed to change a a function i had which started a 20 min delay when i click the button. but like one of the other people i now find when i start the tkinter .py file it runs the function with out me clicking the button. and clicking the button does not run the function anymore. code for the button /// butreturn1feed= tk.Button(root, text=("20 MINUTE ") + ("FEED TIMER"),wraplength=70, borderwidth=8, font=(ftb),bg="red", height=13, command= threading.Thread(target=rtn1feed).start()) and the function is def rtn1feed(): feederon() bus.write_pin(12, 0) # Uv outlet 4 time.sleep(3) GPIO.output(20, GPIO.LOW) #return pump 1 time.sleep(3) GPIO.output(16, GPIO.LOW) #return pump 2 time.sleep(3) GPIO.output(7, GPIO.LOW) #gyre pump time.sleep(3) GPIO.output(26, GPIO.LOW) #power head 1 time.sleep(3) GPIO.output(19, GPIO.LOW) #power head 2def rtn1feed(): feederon() bus.write_pin(12, 0) # Uv outlet 4 any ideas what i have done wrong?
@Codemycom4 жыл бұрын
Really weird. Are you calling that rtn1feed() function from anywhere else in the program?
@modelrailwaytheeasyway97434 жыл бұрын
Codemy.com no it’s only used in conjunction with that button. Which surprised me too. The only thing I can think is I am running Tkinter in a class which I use to loops to update some labels and they read GPIO states.
@Codemycom4 жыл бұрын
@@modelrailwaytheeasyway9743 Ah yeah, could be...
@Codemycom4 жыл бұрын
try leaving off the () from .start()
@modelrailwaytheeasyway97434 жыл бұрын
Codemy.com wow cheers John that’s sorted it keep up the great video’s
@chiefmiester38013 жыл бұрын
To those of you who's function gets executed before the button is clicked. Try this command=lambda:threading.Thread(target="___________").start()).pack()
@andrewburris17673 жыл бұрын
What about passing args to the function? Use lambda?
@Codemycom3 жыл бұрын
give it a try
@richardspahn13203 жыл бұрын
an example of how to do this: t1=threading.Thread(target=myFunction,args=(arg1,)) #args takes a tuple
@andrewa75593 жыл бұрын
you Taught me the concept well but i keep stumbling into this error: RuntimeError: main thread is not in loop how do I resolve this
@Codemycom3 жыл бұрын
you have an error in your code. it has to be exactly like the video...is your root.mainloop() the last line of code?
@andrewa75593 жыл бұрын
The last line of my code is a function. root.mainloop is the penultimate code. This is because I’m making a project for school so I cannot make it identical to yours unfortunately
@Codemycom3 жыл бұрын
@@andrewa7559 root.mainloop() has to be the last line. That’s the problem.
@parasgtr1984 Жыл бұрын
how to make button that stops the thread?
@Iqbalsharib42 жыл бұрын
Getting error when trying to run multiple times "thread can only be started once"
@miamisatodelle25344 жыл бұрын
Nice tutorial, detail and easy to follow tutorial. I have a question can someone help me. So I want to run both tkinter function (for animation) and pyttsx for the audio. But one of them end up waiting for the first function to finish.can someone help me? Thanks
@miamisatodelle25344 жыл бұрын
The code example is: Def animate(file,loop,wait): "animate using tkinter" Def talk(word): "engine.say(word)" "engine.runAndWait" While True: If keyboard.is_pressed('a'): "Run both animate and talk"
@muhanad1022 жыл бұрын
Is there a problem is I updated the UI using a non-main thread?