11
11
root .iconbitmap ('Python Tkinter Build a Geography Flashcard VIII/avatar.ico' )
12
12
root .geometry ("500x600" )
13
13
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
+
14
50
# Create Addition math flashcards
15
51
def add ():
16
52
hide_all_frames ()
17
53
add_frame .pack (fill = "both" , expand = 1 )
18
54
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 )
20
56
pic_frame = Frame (add_frame , width = 400 , height = 300 )
21
57
pic_frame .pack ()
22
58
23
59
# 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 )
27
64
#math_sign = Label(pic_frame)
28
65
29
66
# Create 3 labes inside our pic frame, frame
67
+ global add_1
68
+ global add_2
30
69
add_1 = Label (pic_frame )
31
70
add_2 = Label (pic_frame )
32
71
math_sign = Label (pic_frame , text = "+" , font = ("Helvetica" , 28 ))
@@ -50,12 +89,16 @@ def add():
50
89
add_2 .config (image = add_image2 )
51
90
52
91
# Create anwer box and button
92
+ global add_answer
53
93
add_answer = Entry (add_frame , font = ("Helvetica" , 18 ))
54
94
add_answer .pack (pady = 50 )
55
95
56
- add_answer_button = Button (add_frame , text = "Answer" )
96
+ add_answer_button = Button (add_frame , text = "Answer" , command = answer_add )
57
97
add_answer_button .pack ()
58
98
99
+ global answer_message
100
+ answer_message = Label (add_frame , text = "" , font = ("Helvetica" , 18 ))
101
+ answer_message .pack (pady = 20 )
59
102
60
103
# Create Radomizing state function
61
104
def random_state ():
@@ -267,5 +310,4 @@ def hide_all_frames():
267
310
# addition Frame
268
311
add_frame = Frame (root , width = 500 , height = 500 )
269
312
270
-
271
313
root .mainloop ()
0 commit comments