很多人都说tkinter不行,这没有,那没有,其中就包括窗口样式自定义。其实这些都可以用代码自己解决,为了方便其他使用tkinter的人,我将我之前写的代码贴出来
Toplvel.py
#本代码基于MIT协议开源
import tkinter as tk
try:
import mss
from PIL import Image
from PIL import ImageTk
graber = mss.mss()
enable_grab = 1
except:
enable_grab = 0
#enable_grab = 0
############### StyledToplevel ###############
class Toplevel(tk.Toplevel):
"""
a Toplevel with Style
initalizal configure:
eight risizers -> Toplevel.rp_
a titlebar -> Toplevel.title
you can change the function _configure_size
to change Toplevel's action
please use like a normal Toplevel.
"""
def __init__(self,*a,**b):
super(self.__class__,self).__init__(*a,**b)
self.overrideredirect(1)
self._icon = tk.Toplevel(self)
self._grab = tk.Label(self._icon)
self._grab.pack(expand=1,fill="both")
self.title = _Titlebar(self,bg="white")
self.title.pack()
self.aera = tk.Frame(self,bg="#f0f0f0")
self.rp_n = tk.Frame(self,cursor="sb_v_double_arrow")
self.rp_s = tk.Frame(self,cursor="sb_v_double_arrow")
self.rp_w = tk.Frame(self,cursor="sb_h_double_arrow")
self.rp_e = tk.Frame(self,cursor="sb_h_double_arrow")
self.rp_nw = tk.Frame(self,cursor="size_nw_se")
self.rp_ne = tk.Frame(self,cursor="size_ne_sw")
self.rp_sw = tk.Frame(self,cursor="size_ne_sw")
self.rp_se = tk.Frame(self,cursor="size_nw_se")
self._setup()
self.geometry("200x200+0+0")
self._configure_size()
def _setup(self):
self._resizable_w = 1
self._resizable_h = 1
self._zoom = 0
self._zoomable = 1
self._icon.bind("" ,self._icon_focusin,1)
self.rp_n.bind("" ,_move_n,1)
self.rp_s.bind("" ,_move_s,1)
self.rp_w.bind("" ,_move_w,1)
self.rp_e.bind("" ,_move_e,1)
self.rp_nw.bind("" ,_move_nw,1)
self.rp_ne.bind("" ,_move_ne,1)
self.rp_sw.bind("" ,_move_sw,1)
self.rp_se.bind("" ,_move_se,1)
self._icon_trace()
self._update_size()
def _configure_size(self):
self.update()
# geo = self.geometry()
# w,h = geo.split("x")
# h,x,y = h.split("+")
# w,h,x,y =