This code creates a window with a welcome message and two labels. The labels are blank and will later be updated with the math problem and the answer. It then creates two buttons: one to display the answer, and one to generate a new math problem.
The generate function assigns two numbers and a sign at random, and depending on the sign assigns either addition or subtraction as the problem. It also sets the global variable answer to the correct answer for that problem. Finally, it displays the window.
Check out the Mental Arithmetic Master on GitHub: