我无法理解是什么触发了以下错误。
这是错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File line 26, in print_sel
dob.index(INSERT, cal.selection_get())
TypeError: index() takes 2 positional arguments but 3 were given
这是我的代码:
def calendar():
def print_sel():
dob.index(INSERT, cal.selection_get())
top = Toplevel(root)
top.title("Select Registration Date")
cal = Calendar(top, font="Arial 14", selectmode='day', locale='en_US',
cursor="hand1", year=2019, month=4, day=4)
cal.pack(fill="both", expand=True)
Button(top, text="ok", command=print_sel).pack()
dob=Entry(Registration_Frame,style='TEntry')
dob.grid(row=3,column=1,columnspan=2,sticky=NSEW)
Button(Registration_Frame, text='Select',command=calendar,width=5,style='TButton').grid(row=3,column=3)
答案 0 :(得分:1)
您将.insert()
方法与index()
混淆了;后者仅需一个参数,并将在输入框中移动更长的文本,以将给定索引处的字符显示为最左侧可见的字符。
只需将.index()
替换为.insert()
:
dob.insert(INSERT, cal.selection_get())