diff --git a/aliens.py b/aliens.py index 94926f8..09d38eb 100644 --- a/aliens.py +++ b/aliens.py @@ -17,3 +17,24 @@ def alien_table(index): 12: "Heatblast", # TODO: Add more aliens }.get(index, "ERROR") + + +def image_display(index): + return { + + 0: "res/omnitrix.png", + 1: "res/heatblast.png", + 2: "res/nasaSquare.png", + 3: "res/????.jpg", + 4: "res/energy-momentum-relation-equation-epc.jpg", + 5: "res/em1_patch_final.png", + 6: "res/artemis.png", + 7: "XLR8", + 8: "Grey Matter", + 9: "Wildmutt", + 10: "Ghostfreak", + 11: "Wildvine", + 12: "Heatblast", + # TODO: Add more aliens + # TODO: Add proper alien silhouettes + }.get(index, "res/omnitrix.png") diff --git a/ben10.py b/ben10.py index 511cc49..37eab54 100644 --- a/ben10.py +++ b/ben10.py @@ -1,6 +1,7 @@ from tkinter import * from aliens import alien_table from functions import * +from PIL import ImageTk, Image root = Tk() root.title("Omnitrix") @@ -9,26 +10,23 @@ root.geometry("640x480") root.configure(bg="#70b607") # root window parameters +path = "res/omnitrix.png" +img = ImageTk.PhotoImage(Image.open(path)) -def button_press(): - transform() - omnitrix_button.config(image=PhotoImage(file="res/heatblast.png")) -# changes image - - -omnitrix_screen = PhotoImage(file="res/omnitrix.png") -omnitrix_button = Button(root, image=omnitrix_screen, bg="#70b607", - activebackground='#70b607', highlightthickness=0, bd=0, command=button_press) +omnitrix_button = Button(root, bg="#70b607", image=img, + activebackground='#70b607', highlightthickness=0, bd=0,command=button_press) +# TODO: make sound when pressed +omnitrix_button.image = img omnitrix_button.place(relx=0.5, rely=0.5, anchor=CENTER) # middle button omnitrix_left = Button(root, text="<", fg="white", bg="black", - command=count_down, highlightthickness=0, bd=0, height=40, width=4) + command=lambda: count_down(omnitrix_button), highlightthickness=0, bd=0, height=40, width=4) omnitrix_left.pack(side="left") # changes alien button (left) omnitrix_right = Button(root, text=">", fg="white", bg="black", - command=count_up, highlightthickness=0, bd=0, height=40, width=4) + command=lambda: count_up(omnitrix_button), highlightthickness=0, bd=0, height=40, width=4) omnitrix_right.pack(side="right") # changes alien button (right) diff --git a/functions.py b/functions.py index ad0d67e..b2069b5 100644 --- a/functions.py +++ b/functions.py @@ -1,24 +1,39 @@ from aliens import * +from PIL import ImageTk, Image counter = 0 -def count_up(): +def count_up(omnitrix_button): global counter counter += 1 print(counter) + if counter < 0: + path = image_display(counter * -1) + else: + path = image_display(counter) + img = ImageTk.PhotoImage(Image.open(path)) + omnitrix_button.configure(image=img) + omnitrix_button.image = img # keep a reference! - -def count_down(): +def count_down(omnitrix_button): global counter counter -= 1 print(counter) + if counter < 0: + path = image_display(counter * -1) + else: + path = image_display(counter) + img = ImageTk.PhotoImage(Image.open(path)) + omnitrix_button.configure(image=img) + omnitrix_button.image = img # keep a reference! -def transform(): +def button_press(): if counter < 0: print(alien_table(counter * -1)) elif counter == 0: print(alien_table(counter)) elif counter > 0: print(alien_table(counter)) +# ! replace with sound playing function \ No newline at end of file