-
How do you modify a DateEntry from tkcalendar, with customtkinter? |
Beta Was this translation helpful? Give feedback.
Answered by
Akascape
Jun 3, 2024
Replies: 2 comments 1 reply
-
@ZeroPlaya Do you want to change the style of it? |
Beta Was this translation helpful? Give feedback.
1 reply
-
@ZeroPlaya You can use sv_ttk theme with customtkinter to match the style of that entry box. sv_ttk.set_theme("light") Or you can use this ctk date picker class I made: import customtkinter
import ctkdlib # pip install ctkdlib
class CTkDatePicker(customtkinter.CTkToplevel):
def __init__(self,
master,
height=200,
width=200,
**kwargs):
super().__init__(takefocus=1)
self.attach = master
self.height = height
self.width = width
self.overrideredirect(True)
self.attach._canvas.tag_bind("right_parts", "<Button-1>", lambda e: self._iconify())
self.attach._canvas.tag_bind("dropdown_arrow", "<Button-1>", lambda e: self._iconify())
self.attach.bind('<Configure>', lambda e: self._withdraw(), add="+")
self.attach.winfo_toplevel().bind('<Configure>', lambda e: self._withdraw(), add="+")
self.frame = customtkinter.CTkFrame(self)
self.frame.pack(fill="both", expand=True)
self.calendar = ctkdlib.CTkCalendar(self.frame, command=self._pass, **kwargs)
self.calendar.pack(expand=True, fill="both")
self.update_idletasks()
self.deiconify()
self.withdraw()
date = self.calendar.current_date()
self.attach.set(f"{date[0]}/{date[1]}/{date[2]}")
self.hide = True
def _iconify(self):
if self.attach.cget("state")=="disabled": return
if self.winfo_ismapped():
self.hide = False
if self.hide:
self.deiconify()
self.hide = False
self.place_dropdown()
else:
self.withdraw()
self.hide = True
def _withdraw(self):
if self.winfo_ismapped():
self.withdraw()
self.hide = True
def _pass(self, date):
self.attach.set(f"{date[0]}/{date[1]}/{date[2]}")
self._withdraw()
def place_dropdown(self):
x_pos = self.attach.winfo_rootx()
y_pos = self.attach.winfo_rooty() + self.attach.winfo_reqheight()
self.geometry('{}x{}+{}+{}'.format(self.width, self.height, x_pos, y_pos))
if __name__ == "__main__":
root = customtkinter.CTk()
combobox = customtkinter.CTkComboBox(root)
combobox.pack(padx=10, pady=10)
CTkDatePicker(combobox) # just add this line in the combobox/optionmenu
root.mainloop() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ZeroPlaya
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ZeroPlaya You can use sv_ttk theme with customtkinter to match the style of that entry box.
Just add this line:
Or you can use this ctk date picker class I made: