无法调用“wm”命令:应用程序已被销毁

2024-09-29 23:32:37 发布

您现在位置:Python中文网/ 问答频道 /正文

import tkinter as tk
from tkinter import *
import pyautogui
root = tk.Tk()
#label = tk.Label(root, text='you coomand hacking', font=    ('Times New Roman','80'), fg='black', bg='white')
#label.pack()
root.title("Wallpaper") 

wall = PhotoImage(file = "20170227180026_3.gif") 
wall_label = Label(image = wall)
root.geometry(f"{wall.width()}x{wall.height()}")     
root.overrideredirect(True)
currentMouseX,currentMouseY = pyautogui.position()
print(f'{currentMouseX} {currentMouseY}')
root.geometry("+0+0")
root.wm_attributes("-topmost", True)
root.wm_attributes("-disabled", True)
root.wm_attributes("-transparentcolor", "white")
wall_label.place(x = -2,y = -2)
root.after(1000 , root.destroy)
#root.geometry("+{}+{}".format(currentMouseX,currentMouseY))
root.geometry("+{}+{}".format(currentMouseX,currentMouseY))
root.mainloop()
root.after(1000 , root.destroy)
root.geometry("+{}+{}".format(currentMouseX,currentMouseY))

请理解,即使源代码是肮脏的

我想要的是图像跟随鼠标

我试图通过重复图像的消失和出现来跟踪鼠标,但这并不容易


Tags: importtrueformattkinterrootlabelattributestk
1条回答
网友
1楼 · 发布于 2024-09-29 23:32:37

在这里。我让图像跟随鼠标,没有pyautogui

代码:

import tkinter as tk
from tkinter import *
#import pyautogui
root = tk.Tk()
#label = tk.Label(root, text='you coomand hacking', font=    ('Times New Roman','80'), fg='black', bg='white')
#label.pack()
root.title("Wallpaper") 

wall = PhotoImage(file = "20170227180026_3.gif")

c = Canvas(root, height = 1200, width = 1200)
c.pack()
pic = c.create_image(600, 600, image = wall)

def movepic(event):
    x,y = event.x, event.y
    c.coords(pic, x, y)

c.bind_all("<Motion>", movepic)

root.mainloop()

相关问题 更多 >

    热门问题