Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC