python报错:“TypeError: func() takes 0 positional arguments but 1 was given”

import tkinter
from tkinter import ttk
win = tkinter.Tk()
win.title("sunk")
win.geometry("400x400+200+20")
cv = tkinter.StringVar()
com = ttk.Combobox(win, )
com.pack()
# 设置下拉数据
com["value"] = ("黑龙江", "吉林", "辽宁")
com.current(0)
# 绑定事件
def func():
    print("sunc is a good man ")
    print(com.get())
    print(cv.get())
com.bind("<>", func)
win.mainloop()

运行结果:
python报错:“TypeError: func() takes 0 positional arguments but 1 was given”_第1张图片
当选择的时候就报错了,原因是因为没有自定义的函数没有加参数,只需要在
def func(event)加入event参数即可
python报错:“TypeError: func() takes 0 positional arguments but 1 was given”_第2张图片
大部分这种情况都是在函数参数没有加上,只需要加上即可

你可能感兴趣的:(python报错集锦)