2

Im trying to create an upgrader/tycoon game and realised to have the money continuously going up, I would have to start a different process so I can have my GUI which can be used as the money goes up without either stopping the other from working.

What is the best way to do this?

I've looked around on this site and nothing I could find has helped me!

(If you need any more information just let me know!)

  • In Java I would do it with Threads. This looks quite promising https://realpython.com/intro-to-python-threading/ – Paul Erlenmeyer Jul 24 '20 at 05:15
  • Does this documentation help you? http://sebastiandahlgren.se/2014/06/27/running-a-method-as-a-background-thread-in-python/ – Joe Ferndz Jul 24 '20 at 05:15
  • This problem may have already been answered on stack overflow. see this thread https://stackoverflow.com/questions/7168508/background-function-in-python – Joe Ferndz Jul 24 '20 at 05:16

1 Answers1

2

Use threading.

Python has a module named threading, and you need

threading.Thread(target=somefunc).start()

My old answer in the same topic: Here. If you consider adding some code to your question, I am happy to help in threading! Also, if you need help in designing the code, feel free to ask, threads can be messy.

nagyl
  • 1,644
  • 1
  • 7
  • 18
  • Would this work using global variables, so the amount of money/sec would be changed while this is running, so can I just update the global variable and everything works or would I have to stop and restart it every time an upgrade is bought? –  Jul 24 '20 at 05:18
  • I had an answer a while back, same topic. I will link to my answer. It will work with global variables, and you can controll it however you want. – nagyl Jul 24 '20 at 05:20
  • Thank you! Ill let you know if I need any help with the threadding but for now im okay! –  Jul 24 '20 at 05:34