I've been doing programming in tkinter for awhile now and I came across a problem...this problem only shows up after a single part but here is the code...kinda lengthy.if you go to the equip menu and equip bare neck you can't change necklaces again. any help in shortening this or fixing the problem let me know
from Tkinter import *
import random
import operator
global armor, sword, game, pots, ether, player, con, mana, magic, fight, melf, text, combattext, letter, available, held, necklace, neck
area = 0
sword = 0
pots = 20
available = {0,1,2}
held = {0,1,2}
armor = 0
first = ""
last = ""
game = "go"
ether = 5
player = 50
con = 0
mana = 10
magic = 0
fight = "menu"
slime = 0
melf = 0
text = 0
combattext = 0
letter = ""
neck = 1
necklace = {1,2,3}
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
def Healthtext():
global player,mana
if player > 50+5*con:
player = 50+5*con
if mana > 10+magic:
mana = 10+magic
health.configure(text = ("hp:",player,"/",50+5*con,",mana:",mana,"/",10+magic), relief=SUNKEN)
health.after(100, Healthtext)
def textboxtext():
global text
if text == 0:
if last != "":
textbox.configure(text = ("Welcome",first,last,"to","the","world","of","slime","fighter."))
if last == "":
textbox.configure(text = ("Welcome",first,"to","the","world","of","slime","fighter."))
text = -1
if text == 1:
textbox.configure(text = ("You","have",pots,"potions."),fg="black")
text = -1
if text == 2:
textbox.configure(text = ("You","have",ether,"ethers."),fg="black")
text = -1
if text == 3:
textbox.configure(text = "Rested.", fg="blue")
text = -1
if text == 4:
textbox.configure(text = "At least your not naked",fg="black")
text = -1
if text == 5:
textbox.configure(text = "You put on your clothes",fg="black")
text = -1
if text == 6:
textbox.configure(text = "Leather armor gives 1 defence",fg="black")
text = -1
if text == 7:
textbox.configure(text = "You put on your leather armor",fg="black")
text = -1
if text == 8:
textbox.configure(text = "Chainmail gives 2 defence",fg="black")
text = -1
if text == 9:
textbox.configure(text = "You put on some chainmail",fg="black")
text = -1
if text == 10:
textbox.configure(text = "Pointy (1d6)",fg="black")
text = -1
if text == 11:
textbox.configure(text = "You grab your dagger",fg="black")
text = -1
if text == 12:
textbox.configure(text = "This might actually hurt something (1d8)",fg="black")
text = -1
if text == 13:
textbox.configure(text = "You grab your short sword",fg="black")
text = -1
if text == 14:
textbox.configure(text = "Now this is a weapon. (1d10)",fg="black")
text = -1
if text == 15:
textbox.configure(text = "You grab your long sword",fg="black")
text = -1
if text == 16:
textbox.configure(text = "If only you had a necklace",fg="black")
text = -1
if text == 17:
textbox.configure(text = "You take off your necklace",fg="black")
text = -1
if text == 18:
textbox.configure(text = "rejuv necklace gives rejuvination",fg="black")
text = -1
if text == 19:
textbox.configure(text = "You put on your rejuv necklace",fg="black")
text = -1
if text == 20:
textbox.configure(text = "regen necklace gives regeneration",fg="black")
text = -1
if text == 21:
textbox.configure(text = "You put on your regen necklace",fg="black")
text = -1
if text == 22:
textbox.configure(text = ("Welcome","back",first,last),fg="black")
text = -1
textbox.after(100, textboxtext)
health = Label(master, text="")
health.configure(text = ("hp:",player,"/",50+5*con,",mana:",mana,"/",10+magic), relief=SUNKEN)
health.pack()
health.after(100, Healthtext)
textbox = Label(master, text="")
textbox.pack()
textbox.after(100, textboxtext)
self.North = Button(frame, text="North",bg="red",fg="white", command=self.north)
self.North.pack(side=TOP)
self.North.configure(cursor="sb_up_arrow")
self.South = Button(frame, text="South",bg="yellow", command=self.south)
self.South.pack(side=BOTTOM)
self.South.configure(cursor="sb_down_arrow")
self.West = Button(frame, text="West",bg="blue",fg="white", command=self.west)
self.West.pack(side=LEFT)
self.West.configure(cursor="sb_left_arrow")
self.Quit = Button(frame, text="Quit",bg="black",fg="white",command=quit)
self.Quit.pack(side=LEFT)
self.Quit.configure(cursor="pirate")
self.East = Button(frame, text="East",bg="green", command=self.east)
self.East.pack(side=LEFT)
self.East.configure(cursor="sb_right_arrow")
def north(self):
global fight
fight = "1"
root.destroy()
def west(self):
global fight
fight = "2"
root.destroy()
def east(self):
global fight
fight = "4"
root.destroy()
def south(self):
global fight
fight = "3"
root.destroy()
def potions():
global text
text = 1
def ethers():
global text
text = 2
def rest():
global player,mana,text
player = 50+con*5
mana = 10+magic
text = 3
def clothes():
global text
text = 4
def wearclothes():
global text
text = 5
global armor
armor = 0
equip.delete(0,10)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def leather():
global text
text = 6
def wearleather():
global text
text = 7
global armor
armor = 1
equip.delete(0,10)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def chain():
global text
text = 8
def wearchain():
global text
text = 9
global armor
armor = 2
equip.delete(0,10)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def dagger():
global text
text = 10
def wielddagger():
global text
text = 11
global sword
sword = 0
equip.delete(0,10)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def short():
global text
text = 12
def wieldshort():
global text
text = 13
global sword
sword = 1
equip.delete(0,10)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def long():
global text
text = 14
def wieldlong():
global text
text = 15
global sword
sword = 2
equip.delete(0,10)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def neck():
global text
text = 16
def wearneck():
global neck,text
text = 17
neck = 1
equip.delete(0,9)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def rejuv():
global text
text = 18
def wearrejuv():
global neck,text
text = 19
neck = 2
equip.delete(0,9)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def regen():
global text
text = 20
def wearregen():
global neck,text
text = 21
neck = 3
equip.delete(0,9)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
def Save():
global fight
fight = "save"
root.destroy()
def Load():
global fight
fight = "load"
root.destroy()
root = Tk()
menu = Menu(root)
root.config(menu=menu)
File = Menu(menu, tearoff=0)
menu.add_cascade(label="File", menu=File)
File.add_command(label="save", command=Save)
File.add_command(label="load", command=Load)
File.add_separator()
File.add_command(label="exit", command=quit)
inv = Menu(menu, tearoff=0)
menu.add_cascade(label="Inv", menu=inv)
inv.add_command(label="Potions", command=potions)
inv.add_command(label="Ethers", command=ethers)
inv.add_separator()
inv.add_command(label="rest", command=rest)
equip = Menu(menu, tearoff=0)
menu.add_cascade(label="equip", menu=equip)
for x in available:
if armor == 0 and x == 0:
equip.add_command(label="clothes*", command=clothes)
if armor != 0 and x == 0:
equip.add_command(label="clothes", command=wearclothes)
if armor == 1 and x == 1:
equip.add_command(label="leather armor*", command=leather)
if armor != 1 and x == 1:
equip.add_command(label="leather armor", command=wearleather)
if armor == 2 and x == 2:
equip.add_command(label="chainmail*", command=chain)
if armor != 2 and x == 2:
equip.add_command(label="chainmail", command=wearchain)
equip.add_separator()
for x in held:
if sword == 0 and x == 0:
equip.add_command(label="dagger*", command=dagger)
if sword != 0 and x == 0:
equip.add_command(label="dagger", command=wielddagger)
if sword == 1 and x == 1:
equip.add_command(label="short sword*", command=short)
if sword != 1 and x == 1:
equip.add_command(label="short sword", command=wieldshort)
if sword == 2 and x == 2:
equip.add_command(label="long sword*", command=long)
if sword != 2 and x == 2:
equip.add_command(label="long sword", command=wieldlong)
equip.add_separator()
for x in necklace:
if neck == 1 and x == 1:
equip.add_command(label="bare neck*", command=neck)
if neck != 1 and x == 1:
equip.add_command(label="bare neck", command=wearneck)
if neck == 2 and x == 2:
equip.add_command(label="rejuv necklace*", command=rejuv)
if neck != 2 and x == 2:
equip.add_command(label="rejuv necklace", command=wearrejuv)
if neck == 3 and x == 3:
equip.add_command(label="regen necklace*", command=regen)
if neck != 3 and x == 3:
equip.add_command(label="regen necklace", command=wearregen)
app = App(root)
root.title ("movement")
root.geometry('300x200+50+50')
root.mainloop()