When doing that I get this error:
UnboundLocalError: local variable 'num' referenced before assignment.
Here is the whole code I am using:
#!/usr/bin/python
from Tkinter import *
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")
num = 0
temp1 = "I have "
temp2 = "5 "
temp3 = 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()
As you can see it creates a window, a entry box, and three buttons. First you click th "open" button to create a text file , then you enter something in the entry box and press "insert", what was in the entry box is added to the text file along with the value of the variable I'm having a problem with and another string, when your done adding things to the text file you press "close" to close the file and that all there is to it