python tkinter ttk_Python Tkinter ttk calendar

UPDATE: I have fixed the issue and published a new version of tkcalendar.

EDIT: the problem is that in Windows, the drop-down does not open when the downarrow button is clicked. It seems that it comes from the default ttk theme for Windows because it works with other themes. So the workaround is to switch theme and use 'clam' for instance ('alt' should work as well). Meanwhile, I will look into it and see if I can fix the DateEntry for the other themes and release a new version (https://github.com/j4321/tkcalendar/issues/3).

I am not sure what you want to achieve exactly with the DateEntry, but if your goal is to make it look like the one in the picture, it can be done the following way:

import tkinter as tk

from tkinter import ttk

from tkcalendar import DateEntry

from datetime import date

root = tk.Tk()

# change ttk theme to 'clam' to fix issue with downarrow button

style = ttk.Style(root)

style.theme_use('clam')

class MyDateEntry(DateEntry):

def __init__(self, master=None, **kw):

DateEntry.__init__(self, master=None, **kw)

# add black border around drop-down calendar

self._top_cal.configure(bg='black', bd=1)

# add label displaying today's date below

tk.Label(self._top_cal, bg='gray90', anchor='w',

text='Today: %s' % date.today().strftime('%x')).pack(fill='x')

# create the entry and configure the calendar colors

de = MyDateEntry(root, year=2016, month=9, day=6,

selectbackground='gray80',

selectforeground='black',

normalbackground='white',

normalforeground='black',

background='gray90',

foreground='black',

bordercolor='gray90',

othermonthforeground='gray50',

othermonthbackground='white',

othermonthweforeground='gray50',

othermonthwebackground='white',

weekendbackground='white',

weekendforeground='black',

headersbackground='white',

headersforeground='gray70')

de.pack()

root.mainloop()

I created a class inheriting from DateEntry to add the label with today's date below the calendar and to create a black border around the drop-down (self._top_cal is the Toplevel containing the calendar).

Then, I created an instance of MyDateEntry and with all calendar options needed to make it look like the picture. In addition, I used the year, month, day options to define the initial date inside the entry.

Here is the result:

ODqnvO4l.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值