The function firespit can't access any of the code inside of it saying it is unreachable. All the variable inside firespit are also unbound even though I have defined them previously. What i am trying to do is subtract damage of firespit from the health of the opponent. if there is a better way please tell me.
#Set up imports
import tkinter as tk
from tkinter import *
from tkinter.filedialog import *
from tkinter.constants import BOTTOM, LEFT, RIGHT, TOP
import random
from PIL import ImageTk, Image
from tkinter import ttk
#Set up Pokemon
pokemonList = ["Water Turte", "Plot Armour Rat", "Fire Lizard", "Plant with Legs"]
#Pokemon Move lists
fireLizardMoves = {"Firespit":25, "wingbash":15, "bite":20, "flamethrower":1}
plantWithLegsMoves = {"sit":5, "treebash":20, "stomp":25, "naturepower":10}
waterTurtleMoves = {"Water bazuka":25, "sprinkler":20, "SWIM":15,"TurtlePower":3}
plotArmourRatMoves = {"Lightning Bolt":10, "Broken Cpu":25, "SparkyRat":15, "speedyhit":1}
#Pokemon HP
PlayerHp = 0
CompHp = 0
fireLizardHP = 100
PlantWIthLegsHP = 125
WaterTurtleHP = 75
PlotArmourRatHp = 60
#Set Up Gui
menu = tk.Tk()
menu.title("Pokemon Game")
menu.rowconfigure(0, minsize=800, weight=1)
menu.columnconfigure(1, minsize=800, weight=1)
menu.configure(background= 'black')
#Import Image
imgFirelizard = ImageTk.PhotoImage(Image.open("General/FireLizard.PNG"))
imgPlotArmourRat = ImageTk.PhotoImage(Image.open("General/PlotArmourRat.PNG"))
imgPlantWithLegs = ImageTk.PhotoImage(Image.open("General/PlantWithLegs.PNG"))
imgWaterTurtle = ImageTk.PhotoImage(Image.open("General/WaterTurtle.PNG"))
img=[imgFirelizard,imgPlantWithLegs,imgPlotArmourRat,imgWaterTurtle]
#Set up windows
window1 = tk.Toplevel()
window1.withdraw()
window2 = tk.Toplevel()
window2.withdraw()
window3 = tk.Toplevel()
window3.withdraw()
#Different tabs
def choose_your_character():
for items in pokemonList:
window1.title("Choose Your Character")
window1.rowconfigure(0, minsize=800, weight=1)
window1.columnconfigure(1, minsize=800, weight=1)
window1.configure(background= 'black')
frame = Frame(window1, width=150, height=100)
frame.place(anchor='center', relx=0.5, rely=0.5)
label1 = Label(frame, image = imgFirelizard)
label2 = Label(frame, image = imgPlantWithLegs)
label3 = Label(frame, image = imgWaterTurtle)
label4 = Label(frame, image = imgPlotArmourRat)
label1.pack()
label2.pack()
label3.pack()
label4.pack()
menu.withdraw()
window1.deiconify()
def battle_start_fire_Lizard():
global updatedCompHp
window2.rowconfigure(0, minsize=800, weight=1)
window2.columnconfigure(1, minsize=800, weight=1)
window1.withdraw()
window2.deiconify()
window2.configure(background= 'black')
frame1 = Frame(window2, width=2, height=1)
frame1.place(anchor='w', relx=0.2, rely=0.7)
label5 = Label(frame1, image = imgFirelizard)
label5.pack()
frame2 = Frame(window2, width=2, height=1)
frame2.place(anchor='w', relx=0.7, rely=0.2)
PlayerHp = fireLizardHP
CompPokemon = random.choice(img)
#Set opposing pokemone health, moves, and character
if CompPokemon == imgFirelizard:
CompPokemonAttacks = fireLizardMoves
updatedCompHp = CompHp + fireLizardHP
label6 = Label(frame2, image = imgFirelizard)
label6.pack()
elif CompPokemon == imgPlantWithLegs:
CompPokemonAttacks = plantWithLegsMoves
updatedCompHp = CompHp + PlantWIthLegsHP
label7 = Label(frame2, image = imgPlantWithLegs)
label7.pack()
elif CompPokemon == imgWaterTurtle:
CompPokemonAttacks = waterTurtleMoves
updatedCompHp = CompHp + WaterTurtleHP
label8 = Label(frame2, image = imgWaterTurtle)
label8.pack()
elif CompPokemon == imgPlotArmourRat:
CompPokemonAttacks = plotArmourRatMoves
updatedCompHp = CompHp + PlotArmourRatHp
label9 = Label(frame2, image = imgPlotArmourRat)
label9.pack()
#Set up Hp box's
while PlayerHp and updatedCompHp > 0:
playerHpBox = Label(window2, text=PlayerHp, fg='blue', font=("Helvetica", 20))
playerHpBox.place(x=60, y=600)
CompHpBox = Label(window2, text=updatedCompHp, fg='red', font=("Helvetica", 20))
CompHpBox.place(x=1800, y=50)
return updatedCompHp
def firespit():
updatedCompHp -= fireLizardMoves.get("Firespit")
return updatedCompHp
return firespit
def battle_start_Plant_with_Legs():
window1.withdraw()
def battle_start_Water_Turtle():
window1.withdraw()
def battle_start_Plot_Armour_Rat():
window1.withdraw()
def end_program():
menu.destroy()
window1.destroy()
#Create button
btn_main_menu = tk.Frame(menu, relief=tk.RAISED, bd=10)
btn_start = tk.Button(btn_main_menu, text="Start", command=choose_your_character)
btn_quit = tk.Button(btn_main_menu, text="Quit", command=end_program)
btn_choose_character = tk.Frame(window1, relief=tk.RAISED, bd=10)
btn_fireLizard = tk.Button(btn_choose_character, text="That Fire Lizard", command=battle_start_fire_Lizard)
btn_waterTurtle = tk.Button(btn_choose_character, text="Water Turtle", command=battle_start_Water_Turtle)
btn_plantWithLegs = tk.Button(btn_choose_character, text="Plant with Legs", command=battle_start_Plant_with_Legs)
btn_PlotArmourRat = tk.Button(btn_choose_character, text="Rat with Plot Armout", command=battle_start_Plot_Armour_Rat)
btn_fireLizardAttacks = tk.Frame(window2, relief=tk.RAISED, bd=10)
btn_FireSpit = tk.Button(btn_fireLizardAttacks, text="Fire Spit", command = battle_start_fire_Lizard.firespit())
btn_wingbash = tk.Button(btn_fireLizardAttacks, text="Wing Bash", command=CompHp - fireLizardMoves.get("wingbash"))
btn_bite = tk.Button(btn_fireLizardAttacks, text="Bite", command=CompHp - fireLizardMoves.get("bite"))
btn_flamethrower = tk.Button(btn_fireLizardAttacks, text="flamethrower", command=CompHp - fireLizardMoves.get("flamethrower"))
btn_PlantWithLegsAttacks = tk.Frame(window3, relief=tk.RAISED, bd=10)
btn_Sit = tk.Button(btn_PlantWithLegsAttacks, text="Sit")
btn_treebash = tk.Button(btn_PlantWithLegsAttacks, text="Tree bash")
btn_stomp = tk.Button(btn_PlantWithLegsAttacks, text="stopm")
btn_naturepower = tk.Button(btn_PlantWithLegsAttacks, text="nature power")
#Position & Set Size of Buttons
btn_start.grid(row=0, column=0, sticky="ew", padx=400, pady=5)
btn_quit.grid(row=0, column=1, sticky="ew", padx=800, pady=5)
btn_main_menu.grid(row=0, column=0, sticky="sw")
btn_fireLizard.grid(row=0, column=0, sticky="ew", padx=87.5, pady=5)
btn_plantWithLegs.grid(row=0, column=1, sticky="ew", padx=175, pady=5)
btn_waterTurtle.grid(row=0, column=3, sticky="ew", padx=262.5, pady=5)
btn_PlotArmourRat.grid(row=0, column=4, sticky="ew", padx=350, pady=5)
btn_choose_character.grid(row=0,column=0, sticky="sw")
btn_FireSpit.grid(row=0, column=0, sticky="ew", padx=87.5, pady=5)
btn_wingbash.grid(row=0, column=1, sticky="ew", padx=175, pady=5)
btn_bite.grid(row=0, column=2, sticky="ew", padx=262.5, pady=5)
btn_flamethrower.grid(row=0, column=3, sticky="ew", padx=350, pady=5)
btn_fireLizardAttacks.grid(row=1,column=0, sticky="sw")
btn_Sit.grid(row=0, column=0, sticky="ew", padx=87.5, pady=5)
btn_treebash.grid(row=0, column=1, sticky="ew", padx=175, pady=5)
btn_stomp.grid(row=0, column=2, sticky="ew", padx=262.5, pady=5)
btn_naturepower.grid(row=0, column=3, sticky="ew", padx=350, pady=5)
btn_PlantWithLegsAttacks.grid(row=1,column=0, sticky="sw")
#LOOP
menu.mainloop()
firespit. This seems unreasonable. Also its good practice to avoid while loops in context of a GUI, but if you insist to keep it, you could work with if conditions to make it work.