j4321 / tkcalendar

Calendar widget for Tkinter
https://pypi.python.org/pypi/tkcalendar
GNU General Public License v3.0
97 stars 33 forks source link

Using dark titlebar negates tkcalender style #103

Closed hariprasath112 closed 11 months ago

hariprasath112 commented 11 months ago

To make the title bar dark I use the below code

import ctypes as ct
window.update()
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
set_window_attribute = ct.windll.dwmapi.DwmSetWindowAttribute
get_parent = ct.windll.user32.GetParent
hwnd = get_parent(window.winfo_id())
rendering_policy = DWMWA_USE_IMMERSIVE_DARK_MODE
value = 2
 value = ct.c_int(value)
 set_window_attribute(hwnd, rendering_policy, ct.byref(value), ct.sizeof(value))

But when I use the code, the combobox that contains Tkcalender loses its styles and shows up as normal unstyled combobox

image

Fo reference, This is what it looks like without using the above code, image

I'll also add the DateEntry element's code

invoiceDateEntry=DateEntry(invoiceFrame,showothermonthdays=False,showweeknumbers=False,date_pattern='dd/mm/yyyy',month=(int(datetime.now().strftime('%m'))-1),year=(date.today().replace(day=1) - timedelta(days=1)).year)
invoiceDateEntry.grid(row=1,column=1,padx=30,pady=10, sticky="ew")
#invoiceNoEntry.bind('<Return>',lambda e: invoiceDateEntry.focus_set())

Calendar opened (Without dark titlebar code):

image

With Code:

Screenshot (20)

The preset text is also white-colored, hence it is not visible. I use Sun Valley theme sv_ttk

hariprasath112 commented 11 months ago

Found a way around to make it work. Used a library called ntkutils to set dark titlebar

 import ntkutils
 ntkutils.dark_title_bar(root)

then made the window close and restart itself with the below code

python = sys.executable
os.execl(python, python, * sys.argv)