0

I've trying to make a notepad application - here's my current code:

from tkinter import *
top=Tk()
top.title('Mypad')
def save(self,s):
    self.s=filedialog.asksaveasfilename(defaultextension='.txt')
    c=open(self.s,'w')
    w=c.write(str(e.get('1.0','end')))
def close():
    top.destroy()
menubar=Menu(top)
file=Menu(menubar,tearoff=0)
vet=file.add_command(label='Save',command=save)
file.add_separator()
file.add_command(label='Exit',command=close)
menubar.add_cascade(label='File',menu=file)
e=Text()
e.pack(ipady=30)
top.config(menu=menubar)
top.mainloop()

But when I run it and try to save it it is saying like this

Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\Workspace\python\lib\tkinter\__init__.py", line 1482, in __call__
    return self.func(*args)
TypeError: save() missing 2 required positional arguments: 'self' and 's'

What can I do to fix this?

0

1 Answer 1

1

You need to import filedialog first. And you don't need self here & neither s as argument.

from tkinter import *
from tkinter import filedialog
top=Tk()
top.title('Mypad')
def save():
    s=filedialog.asksaveasfilename(defaultextension='.txt')
    c=open(s,'w')
    w=c.write(str(e.get('1.0','end')))
def close():
    top.destroy()
menubar=Menu(top)
file=Menu(menubar,tearoff=0)
vet=file.add_command(label='Save',command=save)
file.add_separator()
file.add_command(label='Exit',command=close)
menubar.add_cascade(label='File',menu=file)
e=Text()
e.pack(ipady=30)
top.config(menu=menubar)
top.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.