deanhystad keeps asking what I am trying to accomplish with my code. The code I previously posted was made to make it easier to follow.
Here is the actual code. Go to addition tables, then threes addition tables to get an idea of what I am trying to do.
import tkinter as tk
root = tk.Tk()
# from tkinter import ttk
myfont = "helvitica 25"
mybg = "light sky blue"
myheight = 4
mywidth = 60
myheight2 = 6
mywidth2 = 20
myheight3 = 3
mywidth3 = 20
labcol = "spring green"
anscol = "yellow"
otherbutcol = "light sky blue"
mypadx =2
mypady=2
class Mathtasks:
# Mathtasks are math activities for young people.
#Choose addition tables threes to test the program
def __init__(self, root):
self.root = root
root.geometry('1200x1200')
self.opening()
#This is the opening Menu
def opening(self):
self.openingframe = tk.Frame(self.root)
self.openingframe.grid(row=0, column=0)
self.kalb = tk.Label(self.openingframe, text="MathTasks", bg=labcol, font=myfont, relief="groove")
self.kalb.config(height=myheight, width=mywidth)
self.kalb.grid(row=1, column=1, sticky=tk.W)
self.clickherebn = tk.Button(self.openingframe, text="Click here to start.", bg=otherbutcol, font=myfont,
relief="groove", command=self.mm)
self.clickherebn.config(height=myheight, width=mywidth)
self.clickherebn.grid(row=3, column=1, sticky=tk.W)
self.quitbn = tk.Button(self.openingframe, text="Quit", font=myfont, bg="red", relief="groove",
command=self.openingframe.quit)
self.quitbn.config(height=myheight, width=mywidth)
self.quitbn.grid(row=4, column=1, sticky=tk.W)
#This is the Main Menu
def mm(self):
self.openingframe.destroy()
self.mmframe = tk.Frame(root)
self.mmframe.grid(row=0, column=0)
self.menu = tk.Menu(self.mmframe)
# Addition Tables
self.add = tk.Menu(self.menu)
self.menu.add_cascade(label="Addition Tables", menu=self.add)
self.add.add_command(label="ones addition table", command=lambda:[self.tbles("a", 1)])
self.add.add_command(label="twos addition table", command=lambda:[self.tbles("a", 2)])
self.add.add_command(label="threes addition table", command=lambda:[self.tbles("a", 3)])
self.add.add_separator()
self.add.add_command(label="fours addition table", command=lambda:[self.tbles("a", 4)])
self.add.add_command(label="fives addition table", command=lambda:[self.tbles("a", 5)])
self.add.add_command(label="sixes addition tables", command=lambda:[self.tbles("a", 6)])
self.add.add_separator()
self.add.add_command(label="sevens addition table", command=lambda:[self.tbles("a", 7)])
self.add.add_command(label="eights addition table", command=lambda:[self.tbles("a", 8)])
self.add.add_command(label="nines addition table", command=lambda:[self.tbles("a", 9)])
self.add.add_separator()
self.add.add_command(label="tens addition table", command=lambda:[self.tbles(a, 10)])
self.add.add_command(label="elevens addition table", command=lambda:[self.tbles(a, 11)])
self.add.add_command(label="twelves addition table", command=lambda:[self.tbles(a, 12)])
# Subtraction Tables
self.sub = tk.Menu(self.menu)
self.menu.add_cascade(label="Subtraction Tables", menu=self.sub)
self.sub.add_command(label="ones subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="twos subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="threes subtraction table",command=lambda:[self.tbles("s", 1)])
self.sub.add_separator()
self.sub.add_command(label="fours subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="fives subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="sixes subtraction tables", command=lambda:[self.tbles("s", 1)])
self.sub.add_separator()
self.sub.add_command(label="sevens subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="eights subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="nines subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_separator()
self.sub.add_command(label="tens subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="elevens subtraction table", command=lambda:[self.tbles("s", 1)])
self.sub.add_command(label="twelves subtraction table", command=lambda:[self.tbles("s", 1)])
# Multiplication Tables
self.multi = tk.Menu(self.menu)
self.menu.add_cascade(label="Multiplication Tables", menu=self.multi)
self.multi.add_command(label="ones multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="twos multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="threes multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_separator()
self.multi.add_command(label="fours multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="fives multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="sixes multiplication tables", command=lambda:[self.tbles("m", 1)])
self.multi.add_separator()
self.multi.add_command(label="sevens multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="eights multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="nines multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_separator()
self.multi.add_command(label="tens multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="elevens multiplication table", command=lambda:[self.tbles("m", 1)])
self.multi.add_command(label="twelves multiplication table", command=lambda:[self.tbles("m", 1)])
# Division Tables
self.div = tk.Menu(self.menu)
self.menu.add_cascade(label="Division Tables", menu=self.div)
self.div.add_command(label="ones division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="twos division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="threes division table", command=lambda:[self.tbles("d", 1)])
self.div.add_separator()
self.div.add_command(label="fours division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="fives division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="sixes division tables", command=lambda:[self.tbles("d", 1)])
self.div.add_separator()
self.div.add_command(label="sevens division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="eights division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="nines division table", command=lambda:[self.tbles("d", 1)])
self.div.add_separator()
self.div.add_command(label="tens division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="elevens division table", command=lambda:[self.tbles("d", 1)])
self.div.add_command(label="twelves division table", command=lambda:[self.tbles("d", 1)])
# Prime Numbers
self.prime = tk.Menu(self.menu)
self.menu.add_cascade(label="Which is the prime number?", menu=self.prime)
self.prime.add_command(label="1 to 10", command=self.iw)
self.prime.add_command(label="10 to 20", command=self.iw)
#Fraction of the pie
self.frac = tk.Menu(self.menu)
self.menu.add_cascade(label="Pie fractions", menu=self.frac)
self.frac.add_command(label="What fraction of the pie is the slice?", command=self.iw)
self.frac.add_command(label="What fraction of the pie is remaining?", command=self.iw)
self.helpmenu = tk.Menu(self.menu)
self.menu.add_cascade(label="Help", command=self.iw)
self.helpmenu.add_command(label="About...", command=self.iw)
self.root.config(menu=self.menu)
#Table brings up a menu where the use chooses an answer to an addition, subtraction, multiplication or division problem.
def tbles(self, asmd, no):
import random
arandomno = random.randrange(1,12)
#This if then stmt is to make up addition, sub, multi and div problems
#Addition Tables
#asmd specifies where to use addition, subtraction, multiplication or division
#prob shows the problem
#ansx and #ansy are incorrect answers to the problem
#corans is the correct answer to the problem
#ans is the list of possible answers to the problem
if asmd == "a":
prob = str(arandomno) + " +" + str(no) + "=" #Show the problem
ansx = no + random.randrange(1,12) #Make a wrong answer
ansy = no + random.randrange(1, 12) # Make a wrong answer
corans = arandomno + no #Calculate the correct answer
ans = [ansx, ansy, corans] # Make a list of answers
#Subtraction
elif asmd == "s":
result = 'High' if x > 10 else 'Low'
prob = str(arandomno) + " -" + str(no)
ansx = no - random.randrange(1,12)
ansy = no - random.randrange(1, 12)
corans = arandomno - no
ans = [ansx, ansy, corans]
#Multiplication
elif asmd == "m":
prob = str(arandomno) + " X" + str(no)
ansx = no * random.randrange(1, 12)
ansy = no * random.randrange(1, 12)
corans = arandomno * no
ans = [ansx, ansy, corans]
#Division
else:
prob = str(arandomno) + " /" + str(no)
ansx = no / random.randrange(1, 12)
ansy = no / random.randrange(1, 12)
corans = arandomno / no
ans = [ansx, ansy, corans]
print (ans)
random.shuffle(ans)
print (ans)
self.mmframe.destroy()
self.mmframe = tk.Frame(root)
self.mmframe.grid(row=0, column=0, sticky=tk.W + tk.E, padx = mypadx, pady = mypady)
self.probsleft = tk.Label(self.mmframe, text="Problems left", bg=labcol, font=myfont, relief="groove")
self.probsleft.config(height=myheight2, width=mywidth2)
self.probsleft.grid(row=1, column=1, sticky=tk.W + tk.E, padx = mypadx, pady = mypady)
self.prob = tk.Label(self.mmframe, text=prob, bg="snow", font=myfont,relief="groove")
self.prob.config(height=myheight2, width=mywidth2)
self.prob.grid(row=1, column=2, sticky=tk.W + tk.E,padx = mypadx, pady = mypady)
self.score = tk.Label(self.mmframe, text="Score", bg=labcol, font=myfont, relief="groove")
self.score.config(height=myheight2, width=mywidth2)
self.score.grid(row=1, column=3, sticky=tk.W + tk.E, padx= mypadx, pady = mypady)
self.answera = tk.Button(self.mmframe, text=ans[0], bg=anscol, font=myfont, relief="groove")
self.answera.config(height=myheight3, width=mywidth2)
self.answera.grid(row=2, column=1, sticky=tk.W + tk.E,padx= mypadx, pady = mypady)
self.answerb = tk.Button(self.mmframe, text=ans[1], bg=anscol, font=myfont, relief="groove")
self.answerb.config(height=myheight3, width=mywidth2)
self.answerb.grid(row=2, column=2, sticky=tk.W + tk.E,padx= mypadx, pady = mypady)
self.answerc = tk.Button(self.mmframe, text=ans[2], bg=anscol, font=myfont, relief="groove")
self.answerc.config(height=myheight3, width=mywidth2)
self.answerc.grid(row=2, column=3, sticky=tk.W + tk.E,padx= mypadx, pady = mypady)
self.instructions = tk.Label(self.mmframe, text="Select the answer from the yellow buttons.", \
font=myfont, bg="light gray", relief="groove", wraplength = 400)
self.instructions.config(height=myheight3, width=mywidth2)
self.instructions.grid(row=4, column=1, sticky=tk.W + tk.E, padx=mypadx, pady= mypady)
self.mainmenu = tk.Button(self.mmframe, text="Go to Main Menu", bg="red",font=myfont, relief="groove")
self.mainmenu.config(height=myheight3, width=mywidth2)
self.mainmenu.grid(row=4, column=2, sticky=tk.W + tk.E, padx=mypadx, pady= mypady)
self.exit = tk.Button(self.mmframe, text="Exit", bg="red", font=myfont, relief="groove")
self.exit.config(height=myheight3, width=mywidth2)
self.exit.grid(row=4, column=3, sticky=tk.W + tk.E, padx=mypadx, pady=mypady)
def iw(self):
pass
m = Mathtasks(root)
root.mainloop()