Python 3 very beginner level...I need a detailed explanation of how to use threa
ID: 3719717 • Letter: P
Question
Python 3 very beginner level...I need a detailed explanation of how to use threading.
My game has multiple functions. There is a graphics window with my scores displayed and a user can click to start game (opens a new graphics window) or exit. I have figured out a way to make the scores appear as is they are moving across the screen using time.sleep() but this interferes with my game. How can I use threading to solve this?
I don't know if this helps but my first_graphics_window() is the only function called in my main function and that interacts with all of my other functions so I still need everything to work together...obviously...
Explanation / Answer
Python by default comes with its own threading mechanism, ironically they are called threads and they come under the threads module, but if you are building a game with py game or tkinter, then you might want to ckeck if the library has support for default threads or not. But in python it is very easy to use threads and find thread safe replacements for tkinter and all others too.
import Threads
and the use Threads.thread() - This will give you a thread that you can run on different cores,
keep in mind its a good idea to use deamon while starting your thread, which will make sure that your program runs safely without intermixing all threads.
And about interaction and finding corelation between how to use threads think of using them when you start a sub process or some indepanent task as in like a event handler,etc.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.