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

Conversation

MustafaHilmiYAVUZHAN
Copy link

There may be mistakes, I suggest you check before adding

@MustafaHilmiYAVUZHAN
Copy link
Author

this is a litlle update for title menu

def __init__(
        self,
        master,
        title_bar_color = "default",
        padx: int = 10,
        width: int = 10,
        x_offset: int = None,
        y_offset: int = None):
        
        super().__init__()

        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.master = master
        if "zoomed" not in self.master.state():
            not_zoomed=1
            self.master.state("zoomed")
        else:
            not_zoomed=0

        master_type = self.master.winfo_name()
        
        if master_type=="tk":
            pass
        elif master_type.startswith("!ctktoplevel"):
            pass
        elif master_type.startswith("!toplevel"):
            pass        
        else:
            raise TypeError("Only root windows/toplevels can be passed as the master!")
        
        self.master.minsize(200,100)
        self.overrideredirect(True)
        if title_bar_color=="default":
            if customtkinter.get_appearance_mode()=="Light":
                title_bar_color = 0xFFFFFF # RGB order: 0xrrggbb             
            else:
                title_bar_color = 0x303030 # RGB order: 0xrrggbb
                
        self.transparent_color = self._apply_appearance_mode(self._fg_color)
        self.attributes("-transparentcolor", self.transparent_color)
        self.resizable(True, True)
        self.transient(self.master)
        self.menu = []

        self.config(background=self.transparent_color)
        self.caption_color = title_bar_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
        if x_offset is None:
            title = self.master.title()
            if len(title)>=1:
                for i in title:
                    if i.islower():
                        self.x_offset += 9
                    else:
                        self.x_offset += 7
            
        self.padding = padx
        if not_zoomed:
            self.master.state("normal")

        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
        
        self.master.bind("<Map>", lambda e: self.withdraw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant