View Single Post
Old Feb 28th, 2006, 10:30 AM   #11
MR.T
Newbie
 
MR.T's Avatar
 
Join Date: Feb 2006
Location: USA,Michigan
Posts: 22
Rep Power: 0 MR.T is on a distinguished road
Ok heres my code with the variables defined in the begining of the program.

#!/usr/bin/python

from Tkinter import *

temp1 = "I have "
temp2 = "5 "
temp3 = open("test.txt","w")
num = 0

def Insert():
             num += 1
	     input = ent.get()
             temp3.write(temp1)
             temp3.write(str(num))
             temp3.write(temp2)
	     temp3.write(input)
	     temp3.write('\n')
	     ent.delete(0,END)	
def Close():
            temp3.close()
def Open():
           open("test.txt","w")

root = Tk()
root.geometry('200x210+350+70')

ent = Entry(root, bg = 'white')
button = Button(root, text = "Insert", command = Insert)
button2 = Button(root, text = "Close File", command = Close)
button3 = Button(root, text = "Open File", command = Open)

ent.pack(anchor = W)
button.pack(padx = 4, pady = 4, anchor= E)
button2.pack(padx = 1, pady = 8, anchor= E)
button3.pack(padx = 3, pady = 15, anchor= E)


root.mainloop()

but I still get the "UnboundLocalError: local variable 'num' referenced before assignment" error.

what could be the problem?
MR.T is offline   Reply With Quote