-
Notifications
You must be signed in to change notification settings - Fork 5
Script
- tkinter
- os
- ctypes
- pillow
- darkdetect
- blurwindow
- plugin.dll (Extend by C)
CLASSES
tkinter.Tk(tkinter.Misc, tkinter.Wm)
CTT
class CTT(tkinter.Tk)
| CTT(theme: str = 'followsystem')
|
| A class for custom titlebar window
|
| Method resolution order:
| CTT
| tkinter.Tk
| tkinter.Misc
| tkinter.Wm
| builtins.object
|
| Methods defined here:
|
| __init__(self, theme: str = 'followsystem')
| Class initialiser
|
| close(self, event=None)
| Close Window
|
| deminsize(self, event)
| Deminsize window
|
| disabledo(self)
| For disalbe button get even't command
|
| dragging(self, event)
| Start drag window
|
| exit_back(self, event=None)
| ...
|
| exit_grey(self, event=None)
| ...
|
| exit_on_enter(self, event=None)
| ...
|
| exit_on_leave(self, event=None)
| Function doc
|
| focusin(self, event)
| When focusin
|
| focusout(self, event)
| When focusout
|
| geometry(self, size)
| Rebuild tkinter's geometry
|
| iconbitmap(self, image)
| Rebuild tkinter's iconbitmap
|
| iconphoto(self, image)
| Rebuild tkinter's iconphoto
|
| max_back(self, event=None)
| ...
|
| max_grey(self, event=None)
| ...
|
| max_on_enter(self, event=None)
| ...
|
| max_on_leave(self, event=None)
| ...
|
| maxsize(self, event=None)
| Maxsize Window
|
| min_back(self, event=None)
| ...
|
| min_grey(self, event=None)
| ...
|
| min_on_enter(self, event=None)
| ...
|
| min_on_leave(self, event=None)
| ...
|
| minsize(self)
| Minsize window
|
| moving(self, event)
| Window moving
|
| popupmenu(self, event)
| Popup menu
|
| resize(self)
| Resize window
|
| settheme(self, theme)
| Set the window's theme
|
| setup(self)
| Window Setup
|
| sg(self, w, h)
| Change the self.w and self.h forcely
|
| title(self, text)
| Rebuild tkinter's title
|
| title_back(self)
| ...
|
| title_grey(self)
| ...
|
| titlebarconfig(self, color={'color': None, 'color_nf': None}, height=30)
| Config for titlebar
|
| titlenameconfig(self, pack='left', font=None)
| Config the titlename
|
| useblur(self, acrylic=True, dark=True)
| Add blur / acrylic effect to window
|
| useicon(self, flag=True)
| Show / forget icon
|
| usemaxmin(self, minsize=True, maxsize=True, minshow=True, maxshow=True)
| Show / Disable min / max button
|
| usetitle(self, flag=True)
| Show / forget titlename
Require : window
def applywindow(window):
""" Apply effect on the target window """
window.overrideredirect(True)
mw.gethwnd()
mw.setwindow()
window.withdraw()
window.deiconify()
Require : theme : str ("followsystem", "light", "dark")
--snip--
Usage:
example = CTT(theme = "dark")
exmaple.mainloop()
Require : text : str (any)
def title(self, text):
""" Rebuild tkinter's title """
self._titletext["text"] = text # Will find a good way to show ... if text is too long
self.wm_title(text)
Usage:
CTT.title("Test")
Require : flag : bool (True, False)
def usetitle(self, flag = True):
""" Show / forget titlename """
if not flag:
self._titletext.pack_forget()
Usage:
CTT.usetitle(False)
Require pack : str ("left", "right", "bottom") font : tuple (fontname : str, fontsize : int, fonttype : str)
def titlenameconfig(self, pack = "left", font = None):
""" Config the titlename """
self.usetitle(False)
if pack == "left":
self._titletext.pack(side = LEFT)
elif pack == "right":
self._titletext.pack(side = RIGHT)
else:
self._titletext.config(justify = "center")
self._titletext.pack(expand = True)
if font:
self._titletext.config(font = font)
Usage:
CTT.titlenameconfig("bottom", font = ("Consolas", 11, "italic"))
Require : flag : bool (True, False)
def useicon(self, flag = True):
""" Show / forget icon """
if not flag:
self._titleicon.pack_forget()
Usage:
CTT.useicon(False)
Require : image : any : str (any)
def iconphoto(self, image):
""" Rebuild tkinter's iconphoto """
self._icon = Image.open(image)
self._icon = self._icon.resize((16, 16))
self._img = ImageTk.PhotoImage(self._icon)
self._titleicon["image"] = self. _img
self.wm_iconphoto(self._img)
Usage:
CTT.iconphoto("tk.png")
Require : image : str (any)
def iconbitmap(self, image):
""" Rebuild tkinter's iconbitmap """
self._icon = Image.open(image)
self._icon = self._icon.resize((16, 16))
self._img = ImageTk.PhotoImage(self._icon)
self._titleicon["image"] = self. _img
self.wm_iconbitmap(image)
Usage:
CTT.iconbitmap("tk.ico")
Require : minsize : bool (True, False), maxsize : bool (True, False), minshow : bool (True, False), maxshow : bool (True, False)
def usemaxmin(self, minsize = True, maxsize = True, minshow = True, maxshow = True):
""" Show / Disable min / max button """
if not minshow:
self._titlemin.pack_forget()
elif not minsize:
self.min_on_enter(None)
self._titlemin["command"] = self.disabledo
self._titlemin.unbind("<Leave>")
self._titlemin.unbind("<Enter>")
if not maxshow:
self._titlemax.pack_forget()
elif not maxsize:
self.max_on_enter(None)
self._titlemax["command"] = self.disabledo
self._titlemax.unbind("<Leave>")
self._titlemax.unbind("<Enter>")
Usage:
CTT.usemaxmin(False, False, True, False)
Require: w : int, h : int
def geometry(self, w, h):
""" Change the self.w and self.h forcely """
self.w, self.h = w, h
self.sg("%sx%s" % (self.w, self.h))
Usage:
CTT.geometry("114x514")
Require size : str ("%dx%d+%d+%d", int, int, int, int)
def sg(self, size):
""" Rebuild tkinter's geometry """
if self.w and self.h:
pass
else:
self.w, self.h = size.split('x')[0], size.split('x')[1]
self.wm_geometry(size)
Usage:
CTT.sg("11x45+1+4")
Require : theme : str ("dark", "light")
def settheme(self, theme):
""" Set the window's theme """
if theme == "dark":
self.theme = "dark"
self.bg = self.colors["dark"]
self.nf = self.colors["dark_nf"]
self.fg = "light"
self["background"] = self.colors["dark_bg"]
else:
self.theme = "light"
self.bg = self.colors["light"]
self.nf = self.colors["light_nf"]
self.fg = "dark"
Usage:
CTT.settheme("dark")
Require : acrylic : bool (True, False), dark : bool (True, False) [Can use isDark() / isLight() as a arg]
def addblur(self, acrylic = True, dark = isDark()):
""" Add blur / acrylic effect to window """
if dark:
self.focus_force()
hwnd = windll.user32.GetForegroundWindow()
blur(hwnd = hwnd, hexColor = '#91203801',Dark = dark, Acrylic = acrylic)
Usage:
CTT.addblur(False, isLight())
from custom import CTT, Y, isDark # Load "CTT" class (You also can load X, TOP... from custom.py)
from tkinter.ttk import Entry # From tkinter.ttk import Entry
from sv_ttk import set_theme # Optional, You can use sun-valley-ttk theme
example = CTT()
example.title("CTT example") # Optional
example.geometry(980, 560) # Optional
# example.iconbitmap(...) # Optional
entry = Entry(example.titlebar, width = 30) # You can also replace with other widget
entry.pack(pady = 2, padx = 2, fill = Y) # You can also change a way to pack like : grid?
if isDark: set_theme("dark")
else: set_theme("light")
example.mainloop()