Skip to content

Commit 6f3a989

Browse files
Python Tkinter Build a Geography Flashcard VIII update 05-08-2020
1 parent 4f5967b commit 6f3a989

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

Python Tkinter Build a Geography Flashcard VIIi/buildGeographyFlashcardVIII.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,61 @@
1111
root.iconbitmap('Python Tkinter Build a Geography Flashcard VIII/avatar.ico')
1212
root.geometry("500x600")
1313

14+
# Create flashcard randomization
15+
def math_random():
16+
17+
# Generate a random number
18+
global num_1
19+
global num_2
20+
num_1 = randint(0, 9)
21+
num_2 = randint(0, 9)
22+
#math_sign = Label(pic_frame)
23+
24+
global add_image1
25+
global add_image2
26+
27+
card1 = "Python Tkinter Build a Geography Flashcard VIII/flashcards/" + str(num_1) + ".jpg"
28+
card2 = "Python Tkinter Build a Geography Flashcard VIII/flashcards/" + str(num_2) + ".jpg"
29+
30+
add_image1 = ImageTk.PhotoImage(Image.open(card1))
31+
add_image2 = ImageTk.PhotoImage(Image.open(card2))
32+
33+
# put flashcard images on the screen
34+
add_1.config(image=add_image1)
35+
add_2.config(image=add_image2)
36+
37+
38+
# Create addition answer function
39+
def answer_add():
40+
answer = num_1 + num_2
41+
if int(add_answer.get()) == answer:
42+
response = "Correct " + str(num_1) + " + " + str(num_2) + " = " + str(answer)
43+
else:
44+
response = "Wrong " + str(num_1) + " + " + str(num_2) + " = " + str(answer) + " Not " + add_answer.get()
45+
46+
answer_message.config(text=response)
47+
add_answer.delete(0, "end")
48+
math_random() #funtion math_ramdom
49+
1450
# Create Addition math flashcards
1551
def add():
1652
hide_all_frames()
1753
add_frame.pack(fill="both", expand=1)
1854

19-
add_label = Label(add_frame, text="Addition Flashcards", font=("Helvetica", 18)).pack(pady=15)
55+
add_label = Label(add_frame, text="Addition Flashcards", font=("Helvetica", 18)).pack(pady=5)
2056
pic_frame = Frame(add_frame, width = 400, height=300)
2157
pic_frame.pack()
2258

2359
# Generate a random number
24-
global rando
25-
num_1 = randint(0, 10)
26-
num_2 = randint(0, 10)
60+
global num_1
61+
global num_2
62+
num_1 = randint(0, 9)
63+
num_2 = randint(0, 9)
2764
#math_sign = Label(pic_frame)
2865

2966
# Create 3 labes inside our pic frame, frame
67+
global add_1
68+
global add_2
3069
add_1 = Label(pic_frame)
3170
add_2 = Label(pic_frame)
3271
math_sign = Label(pic_frame, text="+", font=("Helvetica", 28))
@@ -50,12 +89,16 @@ def add():
5089
add_2.config(image=add_image2)
5190

5291
# Create anwer box and button
92+
global add_answer
5393
add_answer = Entry (add_frame, font=("Helvetica", 18))
5494
add_answer.pack(pady=50)
5595

56-
add_answer_button = Button(add_frame, text="Answer")
96+
add_answer_button = Button(add_frame, text="Answer", command=answer_add)
5797
add_answer_button.pack()
5898

99+
global answer_message
100+
answer_message = Label(add_frame, text="", font=("Helvetica", 18))
101+
answer_message.pack(pady=20)
59102

60103
# Create Radomizing state function
61104
def random_state():
@@ -267,5 +310,4 @@ def hide_all_frames():
267310
# addition Frame
268311
add_frame = Frame(root, width=500, height=500)
269312

270-
271313
root.mainloop()

0 commit comments

Comments
 (0)