-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhow_to_play.py
More file actions
38 lines (29 loc) · 1.13 KB
/
Copy pathhow_to_play.py
File metadata and controls
38 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# how_to_play.py
import tkinter as tk
class HowToPlay:
def __init__(self, root, images, on_main_menu):
self.root = root
self.images = images
self.on_main_menu = on_main_menu
self.index = 0
# Setting up the UI elements
self.image_label = tk.Label(self.root)
self.image_label.pack(pady=20)
self.next_button = tk.Button(self.root, text="Next", command=self.next_image)
self.next_button.pack()
# Show the first image
self.show_image(self.index)
def show_image(self, index):
image = self.images[index]
photo = tk.PhotoImage(file=image)
self.image_label.config(image=photo)
self.image_label.image = photo # keep a reference!
# If it's the last image, change button text to "Main Menu"
if index == len(self.images) - 1:
self.next_button.config(text="Main Menu")
def next_image(self):
self.index += 1
if self.index < len(self.images):
self.show_image(self.index)
else:
self.on_main_menu() # Call the passed in function to show the main menu