user3700072
user3700072

Reputation: 39

tkinter Text.get() raises a TypeError exception

from tkinter import *

def save_d():
    files = open("mp3list.txt","a")
    files.write("title :\n")
    files.write("%s" % lists.get())
    files.write("appraisal :\n")
    files.write("%s\n" % appraisal.get())
    lists.delete(0,END)
    appraisal.delete("1.0",END)

def read_f(file):
    lists = []
    lists_f = open(file)
    for line in lists_f:
        lists.append(line.rstrip())
    return lists

app = Tk()
app.title(" MP3 Player " )

Label(app,text = "lists:").pack()
lists = StringVar()
lists.set(None)
options = read_f("mp3.txt")
OptionMenu(app,lists,*options).pack()

Label(app,text = "appraisal:").pack()
appraisal = Text(app)
appraisal.pack()

Button(app,text = "Save",command = save_d).pack()
app.mainloop()

Exception:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python33\lib\tkinter\__init__.py", line 1489, in __call__
    return self.func(*args)
  File "C:\Users\J\Desktop\mp3.py", line 8, in save_d
    files.write("%s\n" % appraisal.get())
TypeError: get() missing 1 required positional argument: 'index1'

Why does the error occur? How can I fix this?

Upvotes: 3

Views: 7829

Answers (1)

Brionius
Brionius

Reputation: 14118

You need to pass the Text.get() function a start and stop index indicating what part of the text in the Text widget you want.

If you want to get all the text in the Text widget, you can use

appraisal.get('1.0', END)

(Documentation for Text.get)

Upvotes: 8

Related Questions