This is the 23rd day of my participation in the August More Text Challenge.More challenges in August
Hello, I am white and white.
Here are some scripts to share with you: Play with Python on your PC, build your own wallpaper changer, lock screen on your PC, and wireless pop-ups.
Modify the desktop wallpaper
Tool use
Development environment: python3.7, Windows10
Use toolkits: Win32API, Win32CON, Win32GUI, OS, random
Win32 tools download command:
pip install pywin32
Copy the code
Project analysis
Desktop data information is saved in the contents of the registry, view the registry method: window key + R key input: regedit data is saved in the second Control Panel\Desktop subitem
Open the registry through win32api to select the corresponding subitem of configuration to generate the corresponding handle
k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, 'Control Panel\Desktop', 0, win32con.KEY_SET_VALUE)
Copy the code
Adjust desktop Style stretch Mode 2 Stretch Wallpaper 0 Center wallpaper 6 Fit 10 Fill
Prepare the image wallpaper that needs to be modified (the wallpaper data is collected by crawler technology)
Win32gui submits data to change the desktop to its own desktop wallpaper
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, img_path, win32con.SPIF_SENDWININICHANGE)
Copy the code
The source code to share
PIP install pyWin32 import Win32con import Win32GUI import OS # Import time # def set_wallpaper(): Path = os.listdir(r' picture folder ') for I in path: K = win32api.regOpenKeyex (win32con.hkey_current_user, 'Control Panel\Desktop', 0, win32con.key_set_value) # 2 "WallpaperStyle", 0, win32con.REG_SZ, '2') win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, img_path, win32con.SPIF_SENDWININICHANGE) time.sleep(10) set_wallpaper()Copy the code
Computer unlimited lock screen
Tool use
Development environment: python3.7, Windows10
Ctypes is Python’s external library of functions. It provides C-compatible data types and allows functions in DLLS or shared libraries to be called. You can use this module to encapsulate these libraries in pure Python. Use user32.dll at the bottom of the operating system to lock the screen
def lock_windows():
while True:
user = windll.LoadLibrary("user32.dll")
user.LockWorkStation()
lock_windows()
Copy the code
Code to provide you can try their own
Package method: PyInstaller
Pyinstaller -f Your file nameCopy the code
After packing, you can give it to your friends and colleagues to try (for the sake of friendship between friends and colleagues, it is best to add a delay operation).
Infinite popup window
You should have known about Panda Burning incense before (similar, if there is no relationship with me) through the OS module to open the CMD window page (make sure it is an option in the environment variable)
for i in range(2000):
os.system('start cmd')
Copy the code
Start taskkill /f /im cmd.exe /t
I am white and white I, a program yuan like to share knowledge ❤️ if there is no contact with this piece of programming friends see this blog, found that can not program or want to learn, you can directly leave a message + private I ah [thank you very much for your likes, favorites, attention, comments, one key four even support]