proper image switching/garbage colection fix

This commit is contained in:
superdimensional 2021-04-30 03:47:00 -04:00
parent 8cdd98ab53
commit be3893a4a3
3 changed files with 49 additions and 15 deletions

View file

@ -17,3 +17,24 @@ def alien_table(index):
12: "Heatblast", 12: "Heatblast",
# TODO: Add more aliens # TODO: Add more aliens
}.get(index, "ERROR") }.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")

View file

@ -1,6 +1,7 @@
from tkinter import * from tkinter import *
from aliens import alien_table from aliens import alien_table
from functions import * from functions import *
from PIL import ImageTk, Image
root = Tk() root = Tk()
root.title("Omnitrix") root.title("Omnitrix")
@ -9,26 +10,23 @@ root.geometry("640x480")
root.configure(bg="#70b607") root.configure(bg="#70b607")
# root window parameters # root window parameters
path = "res/omnitrix.png"
img = ImageTk.PhotoImage(Image.open(path))
def button_press(): omnitrix_button = Button(root, bg="#70b607", image=img,
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) 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) omnitrix_button.place(relx=0.5, rely=0.5, anchor=CENTER)
# middle button # middle button
omnitrix_left = Button(root, text="<", fg="white", bg="black", 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") omnitrix_left.pack(side="left")
# changes alien button (left) # changes alien button (left)
omnitrix_right = Button(root, text=">", fg="white", bg="black", 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") omnitrix_right.pack(side="right")
# changes alien button (right) # changes alien button (right)

View file

@ -1,24 +1,39 @@
from aliens import * from aliens import *
from PIL import ImageTk, Image
counter = 0 counter = 0
def count_up(): def count_up(omnitrix_button):
global counter global counter
counter += 1 counter += 1
print(counter) 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(omnitrix_button):
def count_down():
global counter global counter
counter -= 1 counter -= 1
print(counter) 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: if counter < 0:
print(alien_table(counter * -1)) print(alien_table(counter * -1))
elif counter == 0: elif counter == 0:
print(alien_table(counter)) print(alien_table(counter))
elif counter > 0: elif counter > 0:
print(alien_table(counter)) print(alien_table(counter))
# ! replace with sound playing function