JavaScript
x
26
26
1
import tkinter as tk
2
from tkinter import *
3
import pyautogui
4
root = tk.Tk()
5
#label = tk.Label(root, text='you coomand hacking', font= ('Times New Roman','80'), fg='black', bg='white')
6
#label.pack()
7
root.title("Wallpaper")
8
9
wall = PhotoImage(file = "20170227180026_3.gif")
10
wall_label = Label(image = wall)
11
root.geometry(f"{wall.width()}x{wall.height()}")
12
root.overrideredirect(True)
13
currentMouseX,currentMouseY = pyautogui.position()
14
print(f'{currentMouseX} {currentMouseY}')
15
root.geometry("+0+0")
16
root.wm_attributes("-topmost", True)
17
root.wm_attributes("-disabled", True)
18
root.wm_attributes("-transparentcolor", "white")
19
wall_label.place(x = -2,y = -2)
20
root.after(1000 , root.destroy)
21
#root.geometry("+{}+{}".format(currentMouseX,currentMouseY))
22
root.geometry("+{}+{}".format(currentMouseX,currentMouseY))
23
root.mainloop()
24
root.after(1000 , root.destroy)
25
root.geometry("+{}+{}".format(currentMouseX,currentMouseY))
26
Please understand even if the source code is dirty.
What I want is for the image to follow the mouse
I tried to follow the mouse by repeating the image disappearing and appearing, but it is not easy.
Advertisement
Answer
Here. I made the image follow the mouse, without pyautogui
.
Code:
JavaScript
1
22
22
1
import tkinter as tk
2
from tkinter import *
3
#import pyautogui
4
root = tk.Tk()
5
#label = tk.Label(root, text='you coomand hacking', font= ('Times New Roman','80'), fg='black', bg='white')
6
#label.pack()
7
root.title("Wallpaper")
8
9
wall = PhotoImage(file = "20170227180026_3.gif")
10
11
c = Canvas(root, height = 1200, width = 1200)
12
c.pack()
13
pic = c.create_image(600, 600, image = wall)
14
15
def movepic(event):
16
x,y = event.x, event.y
17
c.coords(pic, x, y)
18
19
c.bind_all("<Motion>", movepic)
20
21
root.mainloop()
22