proper image switching/garbage colection fix
This commit is contained in:
parent
8cdd98ab53
commit
be3893a4a3
3 changed files with 49 additions and 15 deletions
21
aliens.py
21
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")
|
||||
|
|
20
ben10.py
20
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)
|
||||
|
||||
|
|
23
functions.py
23
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
|
Loading…
Add table
Reference in a new issue