Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python tkinter to achieve cool mouse trailing effect

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use python tkinter to achieve cool mouse trailing effect". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use python tkinter to achieve cool mouse trailing effect.

Catalogue

First, the system trailing

Second, literary and artistic trailing

Third, practical trailing

Fourth, love tail

Fifth, the running match human tail

Walnut shakes money and tails

7. Girlfriend or wife trailing

Python-tkinter implements all kinds of flirting mouse tails, and the effect pictures are shown:

The trailing of the system has been unable to satisfy us, your girlfriend asked you to replace the mouse trailing with her photo, so that you can see her all the time, whether you agree to this request or not.

Of course, this requirement can be met for a while. Let's take a look at it in detail.

To make a trail, first of all, we need to know the position of the mouse. Is there any way to get the position of the mouse? Of course the answer is yes. Therefore, we refer to the pyautogui module

Pip install pyautogui

First, the system trailing

The first is the simplest one, which can be easily set by setting the mouse tail, which will not be explained in detail here.

Second, literary and artistic trailing

This trailing is not very lethal and insulting, so it adds buff to its work.

The code is as follows:

Import tkinter,timefrom tkinter import * import pyautoguitk = tkinter.Tk () tk.overrideredirect (True) tk ["background"] = "white" tk.wm_attributes ('- transparentcolor', 'white') w = tk.winfo_screenwidth () # get screen width h = tk.winfo_screenheight () # get screen height cn = Canvas (tk, height=w, width=h Bg= "white") cn.pack () def update_test (e): time.sleep (0.1m) cn.delete (tkinter.ALL) tk.update () global a x-maxie yyogpyautogui.position () # get the mouse position tk.geometry ("180x35+%s+%s"% (x-ray 10, y-bag 10) cn.create_text (85,0, text=' my 40-meter broadsword') tk.bind ("", update_test) tk.mainloop () 3, practical tail

This trailing can help you find things you are easy to forget, such as some keyboard shortcuts, some work things, let it move with the mouse to remind you at any time.

The code is as follows:

Import tkinter,timefrom tkinter import * import pyautoguitk = tkinter.Tk () tk.overrideredirect (True) tk ["background"] = "white" tk.wm_attributes ('- transparentcolor', 'white') w = tk.winfo_screenwidth () # get screen width h = tk.winfo_screenheight () # get screen height cn = Canvas (tk, height=w, width=h Bg= "white") cn.pack () def update_test (e): time.sleep (0. 1) cn.delete (tkinter.ALL) tk.update () global a x-maitorie. Position () tk.geometry ("180x35+%s+%s"% (x, y-10)) cn.create_text (85, 0, text='ctrl+c copy\ n ctrl+v paste', anchor='n') tk.bind (", update_test) tk.mainloop () 4, Love tail.

This trail is very harmful to singles, and it is full of love. I want to find someone to get rid of it quickly. Ha ha

Import tkinter,timefrom tkinter import * from PIL import ImageTk, Imageimport pyautoguitk = tkinter.Tk () tk.overrideredirect (True) tk ["background"] = "white" tk.wm_attributes ('- transparentcolor', 'white') image1 = Image.open ("love .jpg") # Open picture image = image1.resize ((50jpg 60)) # set picture size photo = ImageTk.PhotoImage (image) # introduce picture image2 = Image.open ("love .jpg") image3 = image2.resize ) # set picture size photo1 = ImageTk.PhotoImage (image3) # introduce picture w = tk.winfo_screenwidth () # get screen width h = tk.winfo_screenheight () # get screen height cn = Canvas (tk, height=w, width=h, bg= "white") cn.pack () a=2def update_test (e): time.sleep (0.1) cn.delete (tkinter.ALL) tk.update () global a x Y=pyautogui.position () tk.geometry ("100x120+%s+%s"% (x = 10, y / 10)) if astatine 2: cn.create_image (50,50, image=photo1) cn.pack () axi1 else: cn.create_image (50,50, image=photo) cn.pack () a=2tk.bind (", update_test) tk.mainloop () V, running matchman tail

With this trailing, you can replace the picture with other actions, or even come directly to the last cartoon.

The code is as follows:

Import tkinter,timefrom tkinter import * from PIL import ImageTk, Imageimport pyautoguitk = tkinter.Tk () tk.overrideredirect (True) tk.wm_attributes ('- transparentcolor','# E0D9BC') w = tk.winfo_screenwidth () # get screen width h = tk.winfo_screenheight () # get screen height cn = Canvas (tk, height=h, width=w, bg= "white") # bg= "pink" list,list1,a,b= [], [] Image1 = Image.open ("forward match Man / 123 _" + str (I) + ".PNG") # Open the picture image = image1.resize ( ) # set the size of the picture photo = ImageTk.PhotoImage (image) # introduce the picture list.append (photo) image1 = Image.open ("reverse match person / 123 _" + str (I) + ".PNG") # Open the picture image = image1.resize ) # set picture size photo = ImageTk.PhotoImage (image) # introduce picture list1.append (photo) def image (list): global a for i in range (1,8): if a = = 7: a = 1 cn.create_image (50,50, image=list [0]) a + = 1 else: cn.create_image (50,50) Image=list [a]) a + = 1 breakdef update_test (e): time.sleep (0. 1) tk.update () x tk.geometry () tk.geometry () tk.geometry ("100x100+%s+%s"% (x = 10)) global b if x

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report