【发布时间】:2018-08-29 13:04:17
【问题描述】:
我遇到了一个问题,我不知道这是从哪里来的。 由于我的代码太长,我只会分享产生这个错误的函数和我使用它的行(如果有必要我当然可以分享其他部分)
class Label(object):
#constructor
def __init__(self, data, id, filefullpath, AGE, counter):
self.counter = counter
self.filefullpath = filefullpath
self.data = data
self.object_id = id
self.data_length = len(data)
self.AGE = AGE
# GUI
self.root = Tk()
self.root.title("CHOOSE A LABEL")
#Create a listbox with a scrollbar
self.listbox = Listbox(self.root)
type = ['Indifined','a','b','c']
for ind, val in enumerate(type):
self.listbox.insert(ind, val)
self.listbox.bind('<<ListboxSelect>>', self.save)
self.listbox.pack()
Button(self.root, text = "OK" , command = self.root.destroy).pack(side = 'left')
self.root.mainloop()
def get_selected_label(self):
""" get the label entered by the user """
return(self.listbox.get(self.listbox.curselection()))
def save(self):
"""
Save the label entered by the user
"""
# get the label
label = self.get_selected_label()
if len(label) > 0:
for k in range(self.AGE +2): # plus 2 to include age=-1 and age = 0
Informations = Get_Informations(self.data, self.filefullpath, self.counter - k)
Id = Informations.Id()
age = Informations.age()
for ind, val in enumerate(Id):
if self.object_id == val:
age = age[ind]
if age <= self.AGE:
self.data[self.counter - k]["super_clusters"][ind]["label"] = label
else:
break
else:
pass
for k in range(self.counter +1 , len(self.data)):
Informations = Get_Informations(self.data, self.filefullpath, k)
Id = Informations.Id()
age = Informations.age()
if self.object_id in Id :
for ind, val in enumerate(Id):
if self.object_id == val :
age = age[ind]
if age != -1:
self.data[self.counter + k]["super_clusters"][ind]["label"] = label
else:
break
else:
pass
else:
# the track disappeared
break
这是 Python 返回的错误:因为我在调用它时没有传递任何参数来保存我真的不明白这个消息。
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
TypeError: save() takes 1 positional argument but 2 were given
提前谢谢你。
【问题讨论】:
标签: python-3.x class tkinter