Skip to content

a little bit optimized for me and pywinstyles #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions CTkMenuBar/title_menu_win.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
Menu Bar in Title Bar of customtkinter window
Author: Akash Bora
Customized for pywinstyles and Optimized by Mustafa Hilmi YAVUZHAN
"""

import customtkinter
import sys
from sys import platform

class CTkTitleMenu(customtkinter.CTkToplevel):

Expand All @@ -19,10 +20,10 @@ def __init__(

super().__init__()

if not sys.platform.startswith("win"):
if not platform.startswith("win"):
raise OSError("This title menu works only in windows platform, not supported on your system! \nTry the CTkMenuBar instead...")

self.after(10)
#self.after(10)
self.master = master
master_type = self.master.winfo_name()

Expand All @@ -36,8 +37,7 @@ def __init__(
raise TypeError("Only root windows/toplevels can be passed as the master!")

self.master.minsize(200,100)
self.after(100, lambda: self.overrideredirect(True))

self.overrideredirect(True)
if title_bar_color=="default":
if customtkinter.get_appearance_mode()=="Light":
title_bar_color = 0xFFFFFF # RGB order: 0xrrggbb
Expand All @@ -52,7 +52,7 @@ def __init__(

self.config(background=self.transparent_color)
self.caption_color = title_bar_color
self.change_header_color(self.caption_color)

self.x_offset = 40 if x_offset is None else x_offset
self.y_offset = 6 if y_offset is None else y_offset
self.width = width
Expand All @@ -66,7 +66,8 @@ def __init__(
self.x_offset += 7

self.padding = padx

if "zoomed" not in self.master.state():
self.master.after(400,lambda:(self.master.state("zoomed"),self.master.state("normal")))#fixed focus problem why idk
self.master.bind("<Configure>", lambda _: self.change_dimension())
self.master.bind("<Destroy>", lambda _: super().destroy() if not self.master.winfo_viewable() else None)
self.num = 0
Expand All @@ -79,7 +80,7 @@ def _set_appearance_mode(self, mode_string):
else:
self.caption_color = 0x303030 # RGB order: 0xrrggbb

self.change_header_color(self.caption_color)


def add_cascade(self, text=None, postcommand=None, **kwargs):

Expand Down Expand Up @@ -122,11 +123,12 @@ def change_dimension(self):
self.geometry(f"{width}x{height}+{x}+{y}")
self.deiconify()

def change_header_color(self, caption_color):
"""def change_header_color(self, caption_color):
try:
from ctypes import windll, byref, sizeof, c_int
# optional feature to change the header in windows 11
HWND = windll.user32.GetParent(self.master.winfo_id())
DWMWA_CAPTION_COLOR = 35
windll.dwmapi.DwmSetWindowAttribute(HWND, DWMWA_CAPTION_COLOR, byref(c_int(caption_color)), sizeof(c_int))
except: None
"""
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ submenu.add_option(option="value")
| _*other frame parameters_ | other ctk frame parameters can also be passed |

_Credits goes to [LucianoSaldivia](https://github.com/LucianoSaldivia) for providing this dropdown menu class._

_Credits goes to [MustafaHilmiYAVUZHAN](https://github.com/MustafaHilmiYAVUZHAN) for optimized title menu._