tkinter屏幕扇动
from tkinter import * import time import random def shake(): # 获取当前窗口的坐标 Screen_X = root.winfo_x() Screen_Y = root.winfo_y() Screen_width = root.winfo_width() Screen_height = root.winfo_height() # 循环震动 for i in range(50): if i % 2 == 0: swing_value = 50# 摆动幅度 new_X = Screen_X + random.randint(-100, 100) new_Y = Screen_Y + random.randint(-100, 100) else: swing_value = 0# 摆动幅度 new_X = Screen_X new_Y = Screen_Y new_pos = f'{Screen_width}x{Screen_height}+{new_X}+{new_Y}' root.geometry(new_pos) root.update() time.sleep(0.02) root = Tk() root.geometry('500x400+200+200') root.title("闪动测试") btn = Button(root,text="闪动",command=shake) btn.pack() root.mainloop()