Jan-24-2020, 11:49 PM
Thank you so much for your reply, I'm going to try to implement and learn some of the stuff you said in the morning, I've got another question for anybody willing to answer though...
no matter what I come back in the entry box, it returns wrong, but as you can see in my code, it should return correct!
no matter what I come back in the entry box, it returns wrong, but as you can see in my code, it should return correct!
def result(): if str(entry_box) == str(answer): #print("well done!") btnSCS = Button(window, text="Correct!") btnSCS.grid(column=2, row=3) else: #print("wrong!") btnSCSS = Button(window, text="Wrong!") btnSCSS.grid(column=2, row=3)I am not sure why it is coming out like this, and cannot work it out, can somebody please explain what I'm doing wrong here? thanks for all replies!
import random from tkinter import * window = Tk()#creating window window.title("Maths")#title of window window.minsize(width=40, height=40) window.maxsize(width=400000, height=400000) answer = random.randint(2, 2) two = "4 / 2 =", "a baby conceive two years and nine months ago, the answer is the baby's age. ", "864 - 482 - 380 =" three = "426 / 142 =", "1098 - 685 - 410 =", "3 * 1 =" four = "2 Squared", "793 - 406 - 383 =", "2 * 2 =" five = "4596 - 102 - 4489 =", "30 / 6 =", "1 * 5 =" six = "28 - 16 - 6 =", "3 * 2 =", "10 / 2" seven = "56 - 7 - 42 =", "0.7 * 10 = ", "63 / 9 =" eight = "2 Cube", "36 - 12 - 16 =", "55 / 7 =" nine = "3 Squared", "586 - 428 - 149 =", "99 / 11 =" ten = "586 - 926 - 350 =", "80 / 8 =", "10 * 1 =" eleven = "312 - 52 - 249 =", "121 / 11 = 11", "5.5 * 2 =" twelve = "Medium of 9, 12, 7, 16 and 13", "456 - 215 - 229 =", "144 / 12 =" thirteen = "844 - 726 - 105 =", "6.5 * 2 =", "6 + 7 =" fourteen = "652 - 486 - 152 =", "7 * 2 = ", "3.5 * 4 =" fifteen = "986 - 785 - 186 =", "10 + 5 =", "5 * 2 =" sixteen = "4 Square", "786 - 582 - 188 =", "4 * 4 =" seventeen = "147 - 52 - 78 =", "8 + 9 =", "3.4 * 5 =" eighteen = "3874 - 3772 - 3754 =", "3 / 6 =", "2.25 * 8 =" nineteen = "10528 - 7854 - 2655 =", "4.75 * 4 =", "1216 / 64 =" twenty = "206 - 150 - 36 =", "5 * 4 =", "100 / 5 =" twenty_one = "478 - 264 - 193 =", "7 * 3 =", "7 / 3 =" twenty_two = "9875 - 5248 - 4605 =", "5.5 * 4 =", "352 / 16 =" twenty_three = "548 - 321 - 23 =", "5.75 * 4 =", "368 / 16 =" twenty_four = "457 - 326 - 107 =", "6 * 4 =", "8 * 3 =" twenty_five = "5 Squared", "The highest number in our quiz", "if you * this number by 5 you will get 125" def answers(): if answer == 2: lbl = Label(window, text=random.choice(two)) # generate text lbl.grid(column=2, row=4) # place text location btn1.grid_forget() entry_box() submit_btn() #print(random.choice(two)) if answer == 3: print(random.choice(three)) if answer == 4: print(random.choice(four)) if answer == 5: print(random.choice(five)) if answer == 6: print(random.choice(six)) if answer == 7: print(random.choice(seven)) if answer == 8: print(random.choice(eight)) if answer == 9: print(random.choice(nine)) if answer == 10: print(random.choice(ten)) if answer == 11: print(random.choice(eleven)) if answer == 12: print(random.choice(twelve)) if answer == 13: print(random.choice(thirteen)) if answer == 14: print(random.choice(fourteen)) if answer == 15: print(random.choice(fifteen)) if answer == 16: print(random.choice(sixteen)) if answer == 17: print(random.choice(seventeen)) if answer == 18: print(random.choice(eighteen)) if answer == 19: print(random.choice(nineteen)) if answer == 20: print(random.choice(twenty)) if answer == 21: print(random.choice(twenty_one)) if answer == 22: print(random.choice(twenty_two)) if answer == 23: print(random.choice(twenty_three)) if answer == 24: print(random.choice(twenty_four)) if answer == 25: print(random.choice(twenty_five)) """ def guess(): guess = input("What do you think the answer is ? ") """ btn1 = Button(window, text="Are you ready?", command=answers) btn1.grid(column=0, row=1) def entry_box(): e1 = Entry(window) e1.grid(row=0, column=1) def submit_btn(): btnS = Button(window, text="Submit!!", command=result) btnS.grid(column=0, row=8) def result(): if str(entry_box) == str(answer): #print("well done!") btnSCS = Button(window, text="Correct!") btnSCS.grid(column=2, row=3) else: #print("wrong!") btnSCSS = Button(window, text="Wrong!") btnSCSS.grid(column=2, row=3) lbl = Label(window, text="Welcome to my maths game!") # generate text lbl.grid(column=0, row=0) # place text location #btn2 = Button(window, text="Exit!", command=exit) #btn2.grid(column=25, row=25) """ w = Entry(window) w.grid(column=0, row=6) """ window.mainloop()