Ok, well it writes correctly, but how do I make it write to the file on the next line down? And then read it?
The file will look like this:
Stats,Morestats,,,,,,,,
ExpGot,ExpToGain
How do I make it write to the next line after it has finished the initial one?
I also want it to read the line seperately from the firstHere's the code:
[php]#Role Playing Form.py
from Tkinter import *
#Define Global Variables
global Name
global CharHpMax
global CharHpCurrent
global CharMpMax
global CharMpCurrent
global CharStr
global CharDef
global CharMAtt
global CharMDef
global Currentexp
global Requiredexp
#Create the Start window
class Main:
def __init__(self, master):
torch=PhotoImage(file="C:\Python24\Python Progs\Role Playing Form\Images\Title Screen Flames.gif")
grave=PhotoImage(file="C:\Python24\Python Progs\Role Playing Form\Images\TitleScreenGraves.gif")
ankh=PhotoImage(file="C:\Python24\Python Progs\Role Playing Form\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.create)
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 create(self):
nameCreate()
def delete(self):
pass
def load(self):
nameLoad()
#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.
class nameCreate:
def __init__(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)
def enter(self):
global Name
Name = self.entName.get()
print "Character Name:",Name
fileChar = open('Character Data\ '+Name+'.txt',"w")
classCreate()
self.nameInput.destroy()
class nameLoad:
def __init__(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='Load', command=self.load)
self.cmdName.grid(row=1)
def load(self):
global Name
global CharHpMax
global CharHpCurrent
global CharMpMax
global CharMpCurrent
global CharStr
global CharDef
global CharMAtt
global CharMDef
global Currentexp
global Requiredexp
Name = self.entName.get()
fileChar = open('Character Data\ '+Name+'.txt','r')
for line in fileChar:
classInfo=line.split(',')
CharHpMax = classInfo[1]
CharHpCurrent = classInfo[2]
CharMpMax = classInfo[3]
CharMpCurrent = classInfo[4]
CharStr = classInfo[5]
CharDef = classInfo[6]
CharMAtt = classInfo[7]
CharMDef = classInfo[8]
#Stuff about exp here assigned to the Current and Required
#exp stats
mainGame()
#Adds the stats based on what you selected in the form
class classCreate:
def __init__(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):
global Name
global CharHpMax
global CharHpCurrent
global CharMpMax
global CharMpCurrent
global CharStr
global CharDef
global CharMAtt
global CharMDef
global Currentexp
global Requiredexp
fileClass = open('ClassData.txt','r')
for line in fileClass:
classInfo=line.split(',')
print "Name is:", Name
print "This class's stats are:",classInfo
className = classInfo[0]
CharHpMax = classInfo[1]
CharHpCurrent = classInfo[2]
CharMpMax = classInfo[3]
CharMpCurrent = classInfo[4]
CharStr = classInfo[5]
CharDef = classInfo[6]
CharMAtt = classInfo[7]
CharMDef = classInfo[8]
#sets the exp totals for the new game
Currentexp=0
Requiredexp=0
print "The name of the class is: ",className
print "The Character's max HP is: ",CharHpMax
print "The Character's Current Hp is: ",CharHpCurrent
print "The Character's max Mp is: ",CharMpMax
print "The Character's current Mp is: ",CharMpCurrent
print "The Character's Strength is: ",CharStr
print "The Character's Defence is: ", CharDef
print "The Character's Magic Power is: ", CharMAtt
print "The Character's Magic Resistance is: ", CharMDef
fileChar = open('Character Data\ '+Name+'.txt','a')
fileChar.writelines(className+','+CharHpMax+','+CharHpCurrent+','+CharMpMax+','+CharMpCurrent+','+CharStr+','+CharDef+','+CharMAtt+','+CharMDef+','+str(Currentexp)+','+str(Requiredexp))
mainGame()
self.classChoose.destroy()
class mainGame:
def __init__(self):
global Name
global CharHpMax
global CharHpCurrent
global CharMpMax
global CharMpCurrent
global CharStr
global CharDef
global CharMAtt
global CharMDef
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: "+Name)
self.nameLabel.grid(row=1, column=0)
self.HpLabel = Label(self.gameMain, text="HP: "+CharHpMax+"\ "+CharHpCurrent)
self.HpLabel.grid(row=2, column=0)
self.MpLabel = Label(self.gameMain, text="MP: "+CharMpMax+"\ "+CharMpCurrent)
self.MpLabel.grid(row=3, column=0)
self.StrLabel = Label(self.gameMain, text="Strength: "+CharStr)
self.StrLabel.grid(row=4, column=0)
self.DefLabel = Label(self.gameMain, text="Defence: "+CharDef)
self.DefLabel.grid(row=5, column=0)
self.MAttLabel = Label(self.gameMain, text="Magic Power: "+CharMAtt)
self.MAttLabel.grid(row=6, column=0)
self.MDefLabel = Label(self.gameMain, text="Magic Resistance: "+CharMDef)
self.MDefLabel.grid(row=7, column=0)
self.exitButton = Button(self.gameMain, text="Quit?", command=self.quitGame)
self.exitButton.grid(row=0, column=1)
def quitGame(self):
pass
root = Tk()
main=Main(root)
[/php]
And here's the format I'm hoping for for the text file:
Warrior,250,250,20,20,25,30,10,5
0,0