Reputation: 1080
I am attempting to run the following code for a text editor.
def newfile():
current = None
def create_file(entry):
nonlocal current
current = open(entry.get(),'w')
e.master.destroy()
chdir(askdirectory())
name=Tk()
name.title("Name the File?")
prompt=Label(name, text="Enter name for new file:")
prompt.grid(row=0)
e=Entry(name)
e.grid(row=1)
e.insert(0, "Untitled")
create=Button(name, text="Create", command = lambda: create_file(e))
create.grid(row=2, column=3)
name.mainloop()
return current
But I get this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.2/tkinter/__init__.py", line 1402, in __call__
return self.func(*args)
File "<pyshell#1>", line 15, in <lambda>
create=Button(name, text="Create", command = lambda: create_file(e))
File "<pyshell#1>", line 5, in create_file
current = open(entry.get(),'w')
TypeError: an integer is required
It wants an integer argument. Does anyone know what that is?
Upvotes: 0
Views: 197
Reputation: 385820
An instance of the Entry widget does not require any arguments for the get
method. You are calling it correctly. Neither does the standard open
command require an integer. My guess is, one of entry
or open
is not what you think it is. Maybe you have a method or another object with one of those names?
I suggest putting the call to get
and the open on separate lines, to make sure you know which part of that statement is throwing the error:
text = entry.get()
current = open(text, 'w')
Upvotes: 1