tkcalendar 中出现“'int'对象不可调用”错误

0 投票
1 回答
24 浏览
提问于 2025-04-14 16:23

我正在尝试创建一个日历功能,目的是让某一天的单元格背景变成不同的颜色,以显示那天有活动。我使用的是tkinter和tkcalendar。

代码

    testPage=Toplevel()
    testPage.title("New Booking")
    testPage.geometry("1366x768")
    canvas=Canvas(testPage, width=1366, height=768)
    canvas.pack()
    frame=Frame(testPage)
    topbar=canvas.create_rectangle(0,0, 1366,30, fill="gray")
        

    lblDate=canvas.create_text(400,300, text="")
    date=canvas.create_text(50, 100, text="Date: ", font=("Helvetica", 14))
    date_today=datetime.now()
    cal=Calendar(testPage, width=12, background='saddle brown', foreground='white', mindate=date_today, disabledforeground='red')
    cal.place(x=150, y=100)
    day=date(2024, 3, 15)
    cal.calevent_create(day, "", tags="test")
    cal.tag_config("test", background="red")

我遇到的错误出现在这一行 day=date(2024, 3, 15),错误信息是 TypeError: 'int' object is not callable。我尝试过在日期周围加上引号 ("2024", "3", "15"),也试过用连字符连接日期 (2024-3-15)

我是不是还缺少了什么可以尝试的?非常感谢你能给出的任何建议。谢谢!

1 个回答

0

修复了

这一行 day=date(2024, 3, 15) 需要改成 day=datetime(2024, 3, 15)

谢谢!

撰写回答