Python Tkinter一种线性动画的关闭方式
通过更改root.geometry实现动画效果
现在的函数是y=0.6*x,有好的还可以更改
from tkinter import *
import time
import threading
#——————窗口居中———————
def get_screen_size(window):
return window.winfo_screenwidth(),window.winfo_screenheight()
def get_window_size(window):
return window.winfo_reqwidth(),window.winfo_reqheight()
def center_window(root, width, height):
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
root.geometry(size)
#——————关闭过程———————
def close():
for i in range(1000,10,-4):
k = 0.6*i
size = '%dx%d' % (i, k)
center_window(root,i,k)
time.sleep(0.001)
root.destroy()
def hit():#——————创建新线程——————
t = threading.Thread(target=close)
t.start()
root = Tk()
center_window(root,1000,500)
root.protocol("WM_DELETE_WINDOW", hit)
root.mainloop()