相关疑难解决方法(0)

如何在 tkcalendar (Python) 中获取 DateEntry 的选定日期?

我有一个 tkcalendar,它是日历、DateEntry 的预定义小部件,我正在尝试获取用户为 DateEntry 选择的日期。 虽然可以使用“selection_get()”提取日历小部件的选定日期,但我找不到 DateEntry 的任何内容。

我试过 get_date(),get(),_date(), cget(), ._selection() 等等,但它们似乎没有返回/打印用户选择的日期。请帮忙,如果需要任何补充信息,请告诉我

代码[选自一个简单的 tkcalendar 教程]:

import tkinter as tk
from tkinter import ttk
from tkcalendar import Calendar, DateEntry

def calendar_view():
    def print_sel():
        print(cal.selection_get())

    top = tk.Toplevel(root)

    cal = Calendar(top,
                   font="Arial 14", selectmode='day',
                   cursor="hand1", year=2018, month=2, day=5)
    cal.pack(fill="both", expand=True)
    ttk.Button(top, text="ok", command=print_sel).pack()

def dateentry_view():
    top = tk.Toplevel(root)

    ttk.Label(top, text='Choose date').pack(padx=10, pady=10)
    cal = DateEntry(top, width=12, background='darkblue',
                    foreground='white', borderwidth=2)
    cal.pack(padx=10, pady=10)
    print(cal.cget(DateEntry))

root = tk.Tk()
s = ttk.Style(root) …
Run Code Online (Sandbox Code Playgroud)

python tkinter python-3.x tkcalendar

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

python-3.x ×1

tkcalendar ×1

tkinter ×1