封装了部分实用的方法在windows平台下已经测试
提供了任意窗口位置鼠标拖动窗口的支持
from tkinter import Tk
class PfTk(Tk):
"""
Tk的扩展
增加了对鼠标左键拖动的支持
封装了部分功能方法
"""
def __init__(self, title='PfTk', width=300, height=300, bg='white'):
"""
初始化Tk
:param title: str: 窗口标签(默认: PfTk)
:param width: int: 宽度(默认: 300)
:param height: height: 高度(默认: 300)
:param bg: str: 背景色(默认: white)
"""
# 调用父类构造方法
super().__init__()
# 设置窗口大小与居中
self.geometry(f'{width}x{height}+'
f'{int((self.winfo_screenwidth() - width) / 2)}+'
f'{int((self.winfo_screenheight() - height) / 2)}')
# 标题
self.title(title)
# 背景色
self.config(bg=bg)
# 鼠标拖动
self.__motion = False
# 鼠标点击坐标
self.