tkinter Text.get() 引发 TypeError 异常 [英] tkinter Text.get() raises a TypeError exception
本文介绍了tkinter Text.get() 引发 TypeError 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 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?
推荐答案
您需要向 Text.get()
函数传递一个开始和停止索引,指示 Text
你想要的小部件.
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.
如果你想获取Text
小部件中的所有文本,你可以使用
If you want to get all the text in the Text
widget, you can use
appraisal.get('1.0', END)
这篇关于tkinter Text.get() 引发 TypeError 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文