I have the commands all ok, but even though the syntax is correct, the pic won't display. Here's the zip.
chris99 0 Junior Poster
This attachment is potentially unsafe to open. It may be an executable that is capable of making changes to your file system, or it may require specific software to open. Use caution and only open this attachment if you are comfortable working with zip files.
chris99 0 Junior Poster
Please, can I have some assistance?
Ene Uran 638 Posting Virtuoso
Well, this one is tough because the code is frankly a nightmare!
Here are some hints (look at !!!!!!! comments):
#Role Playing Form.py
from Tkinter import *
#Create the Start window
class character(object):
def __init__(self, master):
# \Images is a subfolder of current folder
torch=PhotoImage(file=r".\Images\Title Screen Flames.gif") #!!!!!
grave=PhotoImage(file=r".\Images\TitleScreenGraves.gif") #!!!!!
ankh=PhotoImage(file=r".\Images\TitleScreenAnkh.gif") #!!!!!
self.master = master
self.master.title('Role Playing Form V1.0')
self.master.geometry('250x250+350+450')
self.torchLabelL=Label(self.master, image=torch)
self.torchLabelL.grid(row=0, column=0)
self.cmdCreate = Button(self.master, text='Create Character', command=self.nameCreate)
self.cmdCreate.grid(row=0, column=1)
self.torchLabelR=Label(self.master, image=torch)
self.torchLabelR.grid(row=0, column=2)
self.graveLabelL=Label(self.master, image=grave)
self.graveLabelL.grid(row=1, column=0)
self.cmdDelete = Button(self.master, text='Delete Character', command=self.delete)
self.cmdDelete.grid(row=1, column=1)
self.graveLabelR=Label(self.master, image=grave)
self.graveLabelR.grid(row=1, column=2)
self.ankhLabelL=Label(self.master, image=ankh)
self.ankhLabelL.grid(row=2, column=0)
self.cmdLoad = Button(self.master, text='Load Character', command=self.load)
self.cmdLoad.grid(row=2, column=1)
self.ankhLabelR=Label(self.master, image=ankh)
self.ankhLabelR.grid(row=2, column=2)
self.master.mainloop()
def nameCreate(self):
self.nameInput = Toplevel(root)
self.nameInput.title('Name of Character?')
self.nameInput.geometry('300x100+350+450')
self.lblName = Label(self.nameInput, text='Enter Name Here')
self.lblName.grid(row=0)
self.entName = Entry(self.nameInput)
self.entName.grid(row=0, column=1)
self.cmdName = Button(self.nameInput, text='Enter', command=self.enter)
self.cmdName.grid(row=1)
self.entName.focus() #cursor helper!!!!!
def enter(self):
self.Name = self.entName.get()
print "Character Name:",self.Name
fileChar = open('Character Data\ '+self.Name+'.txt',"w")
self.classCreate()
self.nameInput.destroy()
def classCreate(self):
self.classChoose = Toplevel(root)
self.classChoose.title('Choose your Class')
self.classChoose.geometry('300x200+300+400')
self.labelChoose = Label(self.classChoose, text="Select the class you wish to be")
self.labelChoose.grid(row=0)
self.listClass = Listbox(self.classChoose, height=4)
self.listClass.grid(row=1)
self.listClass.insert(END,"Warrior")
self.confirm = Button(self.classChoose, text="Confirm", command=self.confirm)
self.confirm.grid(row=2)
def confirm(self):
fileClass = open('ClassData.txt','r')
for line in fileClass:
classInfo=line.split(',')
print "Name is:", self.Name
print "This class's stats are:",classInfo
className = classInfo[0]
self.CharHpMax = classInfo[1]
self.CharHpCurrent = classInfo[2]
self.CharMpMax = classInfo[3]
self.CharMpCurrent = classInfo[4]
self.CharStr = classInfo[5]
self.CharDef = classInfo[6]
self.CharMAtt = classInfo[7]
self.CharMDef = classInfo[8]
self.Currentexp=0
self.Requiredexp=10
print "The name of the class is: ",className
print "The Character's max HP is: ",self.CharHpMax
print "The Character's Current Hp is: ",self.CharHpCurrent
print "The Character's max Mp is: ",self.CharMpMax
print "The Character's current Mp is: ",self.CharMpCurrent
print "The Character's Strength is: ",self.CharStr
print "The Character's Defence is: ", self.CharDef
print "The Character's Magic Power is: ", self.CharMAtt
print "The Character's Magic Resistance is: ", self.CharMDef
fileChar = open('Character Data\ '+self.Name+'.txt','a')
fileChar.writelines(className+','+self.CharHpMax+','+self.CharHpCurrent+','+self.CharMpMax+','+self.CharMpCurrent+','+self.CharStr+','+self.CharDef+','+self.CharMAtt+','+self.CharMDef+','+str(self.Currentexp)+','+str(self.Requiredexp))
self.mainGame()
self.classChoose.destroy()
def delete(self):
pass
def load(self):
self.nameLoad()
def nameLoad(self):
self.nameInput = Toplevel(root)
self.nameInput.title('Name of Character?')
self.nameInput.geometry('300x100+350+450')
self.lblName = Label(self.nameInput, text='Enter Name Here')
self.lblName.grid(row=0)
# careful with later ref., self.entName is duplicate within class!!!!!!!!!
# may need choices, or user is stranded!!!!!
self.entName = Entry(self.nameInput)
self.entName.grid(row=0, column=1)
self.cmdName = Button(self.nameInput, text='Load', command=self.loadChar)
self.cmdName.grid(row=1)
self.entName.focus() #cursor helper!!!!!
#Brings up a dialog box for putting the name in.
#The enter button creates a file with name.txt for the title.
#This will be used to store data for that character
def loadChar(self):
self.Name = self.entName.get()
fileChar = open('Character Data\ '+self.Name+'.txt','r')
for line in fileChar:
classInfo=line.split(',')
self.CharHpMax = classInfo[1]
self.CharHpCurrent = classInfo[2]
self.CharMpMax = classInfo[3]
self.CharMpCurrent = classInfo[4]
self.CharStr = classInfo[5]
self.CharDef = classInfo[6]
self.CharMAtt = classInfo[7]
self.CharMDef = classInfo[8]
for line in fileChar:
expinfo=line.split(',')
self.Currentexp = expinfo[0]
self.Requiredexp = expinfo[1]
self.mainGame()
#Adds the stats based on what you selected in the form
def mainGame(self):
self.gameMain = Toplevel(root)
self.gameMain.title('Role Playing Form V 1.0')
self.gameMain.geometry('400x500+350+400')
self.mainLabel = Label(self.gameMain, text="CHARACTER INFO:")
self.mainLabel.grid(row=0, column=0)
self.nameLabel = Label(self.gameMain, text="Name: "+self.Name)
self.nameLabel.grid(row=1, column=0)
self.HpLabel = Label(self.gameMain, text="HP: "+self.CharHpMax+"\ "+self.CharHpCurrent)
self.HpLabel.grid(row=2, column=0)
self.MpLabel = Label(self.gameMain, text="MP: "+self.CharMpMax+"\ "+self.CharMpCurrent)
self.MpLabel.grid(row=3, column=0)
self.StrLabel = Label(self.gameMain, text="Strength: "+self.CharStr)
self.StrLabel.grid(row=4, column=0)
self.DefLabel = Label(self.gameMain, text="Defence: "+self.CharDef)
self.DefLabel.grid(row=5, column=0)
self.MAttLabel = Label(self.gameMain, text="Magic Power: "+self.CharMAtt)
self.MAttLabel.grid(row=6, column=0)
self.MDefLabel = Label(self.gameMain, text="Magic Resistance: "+self.CharMDef)
self.MDefLabel.grid(row=7, column=0)
self.expLabel = Label(self.gameMain, text="Exp Obtained: "+str(self.Currentexp)+" Exp Needed: "+str(self.Requiredexp))
self.expLabel.grid(row=8, column=0)
self.exitButton = Button(self.gameMain, text="Quit?", command=self.quitGame)
self.exitButton.grid(row=0, column=1)
self.fightButton = Button(self.gameMain, text="Fight?", command=self.fight)
self.fightButton.grid(row=1, column=1)
def quitGame(self):
pass
def fight(self):
self.fightWin()
def fightWin(self):
self.fightScreen = Toplevel(root)
self.fightScreen.title('Select an opponent')
self.fightScreen.geometry('400x300+350+350')
self.enemyLabel = Label(self.fightScreen, text="Select enemy")
self.enemyLabel.grid(row=0)
self.enemyList = Listbox(self.fightScreen, height=4)
self.enemyList.grid(row=1)
self.enemyList.insert(END,"Frog Guru")
self.enemyButton = Button(self.fightScreen, text="Fight!", command=self.attack)
self.enemyButton.grid(row=2)
def attack(self):
enemySel=self.enemyList.curselection()[0]
print "Enemy: ",enemySel
fileEn = open('EnemyData\Enemies.txt')
for line in fileEn:
enemyData = line.split(',')
print enemyData
if enemyData[0] == enemySel:
self.enemyName = enemyData[1]
self.enemyHP=enemyData[2]
self.enemyMP=enemyData[3]
self.enemyStr=enemyData[4]
self.enemyDef=enemyData[5]
self.enemyMagAtt=enemyData[6]
self.enemyMagDef=enemyData[7]
self.enemyExp=enemyData[8]
self.fightZone()
def fightZone(self):
enemyPic=PhotoImage(file=r".\Images\_"+self.enemyName+".gif")
self.fightZone = Toplevel(root)
self.fightZone.title('FIGHT!!')
self.fightZone.geometry('400x300+350+350')
self.lblenemyName=Label(self.fightZone, text="Enemy: "+self.enemyName)
self.lblenemyName.grid(row=0, column=0)
self.enemyPic=Label(self.fightZone, image=enemyPic)
self.enemyPic.grid(row=0, column=1)
root = Tk()
main=character(root)
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.