I am trying to build a gambling dice game for fun using Python's Tkinter in Python 3. The error I am having is after the money is taken away from your bank account (it does this in a different function) I want it to go back to the mainloop. So basically I want to exit a function to get back into the main code (which isn't in a function). Any ideas on how?
-
1You need to post the code that you are having an issue with if you want a reasonable answerSneakyTurtle– SneakyTurtle2017-10-23 21:46:46 +00:00Commented Oct 23, 2017 at 21:46
-
1What you are talking about should be automatic. Unless you have some kind of loop in your function that is forever looping.Mike - SMT– Mike - SMT2017-10-23 21:49:29 +00:00Commented Oct 23, 2017 at 21:49
2 Answers
I am not 100% sure what your problem is but it sounds like you might not fully understand how a function works.
In a tkinter application the mainloop() is always looping so once your function has finished the the next task in that loop will run and if no more task are scheduled in that loop the loop will reset.
Take this below code for example.
from tkinter import *
root = Tk()
def some_function():
print("this function just ran")
Button(root, text="Run some func", command = some_function).pack()
root.mainloop()
What we see is a button that allows us to call on some_function and then once that function is over we are "back in" the mainloop() so to speak.
There is nothing you need to do special here unless inside of your function you are running some kind of loop and want to end the loop on some criteria. Then you can use a break line to end that loop.