摄像头画面作为电脑桌面背景

1. 创建文件main.pyw,文件内容

import base64
import io
import os
import threading
import tkinter as tk

import cv2
import pystray
import win32api
import win32con
import win32gui
from PIL import Image, ImageTk
from pystray import MenuItem, Menu


class Window:

    def __init__(self):
        self.window = tk.Tk()
        self.window.geometry("500x300")

        self.canvas = tk.Canvas(self.window, width=320, height=180)
        self.canvas.pack()

        self.label_str = tk.StringVar()
        self.label = tk.Label(self.window, textvariable=self.label_str)
        self.label.pack()

        self.capture = None
        self.delay = 15
        self.show = True
        # 修改壁纸样式
        reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
        win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
        win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0")

    def quit_window(self, icon: pystray.Icon):
        icon.stop()
        self.window.destroy()
        self.show = False

    def show_window(self):
        self.window.deiconify()
        self.show = True

    def on_exit(self):
        self.window.withdraw()

    def init_capture(self):
        try:
            self.label_str.set("摄像头加载中")
            self.capture = cv2.VideoCapture(0)
            self.capture.set(3, 1920)
            self.capture.set(4, 1080)
            self.update_canvas()
            self.label_str.set("摄像头加载完成")
        except:
            self.label_str.set("摄像头加载失败")

    def update_canvas(self):
        ret, frame = self.capture.read()
        if ret:
            file_path = os.getcwd() + "/1.png"
            cv2.imwrite(file_path, frame)
            # 设置壁纸
            win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, file_path, win32con.SPIF_SENDWININICHANGE)
            if self.show:
                img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                img = Image.fromarray(img)
                img = ImageTk.PhotoImage(img.resize((320, 180)))
                self.canvas.imgtk = img
                self.canvas.create_image(0, 0, anchor=tk.NW, image=img)
        # 重复更新画布
        self.window.after(self.delay, self.update_canvas)

    def start(self):
        menu = (MenuItem('显示', self.show_window, default=True), Menu.SEPARATOR, MenuItem('退出', self.quit_window))
        image_bytes = base64.b64decode(
            "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAHrZJREFUeF7tnXmcVNWVx3/nVTctyiYgYa2mEUSMRiMaMdFJJCaaqIkLLpmIgarqqsYkTBaXZDQYNXHG6EwSJwNd1V3VqDju4h41CZooiUYgUYkoEJuuZhVBsAHtpd6Z3ILXFJ1u+r1Xb7tdt/7Rz4e7nPM799v33ffOvZegfkoBpUCPCpDSRimgFOhZAQWIGh1KgYMooABRw0MpoABRY0ApYE8BNYPY003VKhEFFCAlEmjlpj0FFCD2dFO1SkQBBUiJBFq5aU8BBYg93VStElFAAVIigVZu2lNAAWJPNzO1KJuOjNI7eKRGZUcQcsN1HUOJMARMg6DRAGY+TAMOYaACQD8QQmAigHUAOQDtDLSC+UMi2k1AC4M+APH7ALZrOrYy5d4Nod+m0YnUe2aMUmWsKaAAsabXAaX/nowP1nL6FE3TjyLSJhJhAoPHEyPMwFgAXur7EYBmgJqYuVEjrGVgdRlCb41OpN4qws2SruplAKUWes0dsbEVFXwSwCcCdAKA4wCMl8IpQhsYbwB4DeAVOfCyqkTDK1LY7rORCpAeArCuLjZFy+mfZWingfjTBFT5HCunu28D4Y8AXgqBfz96SMvzdMmD4rFO/QoUUIDsE2NjMn5ojjq+pOt0FhHORN8D4uADn9DGOn4Lome1ED89LpZeq0jx9hk5cHo3NswaEmoPXQjGVwE+DxALZPXbp8CyfzxKPqpreGR8df2qUlWlJAdEU+3sGSDtMgIuKtXAW/KbsRRE9+b6ddxTNXvhDkt1JS9cMoA0JmcdrSE0m4ArAIyUPG4+mc8MpjsRoky4uv5Fn4zwtNs+D0g2VX0WwAkwX+Cpsn29M8KLxKgdl0j/X192tc8C0pSKXEKguWB8pi8H0HffCKug8x3hmkyt77a4YECfA2R9MnqxDr4aoJNd0Es12bMCa1jn2yrnZOr6kkh9BpCmVORM0uk6ED7XlwIkmy8MXqHp+Mm4OZnFstnenb3SA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3ynoN6QExXG5KRc4kna5T+0usDwJHazBeYI1/6tZZuY7aaqKxPgOI4ev6ZPRiHXw1QCeb8F8VcUwBflUD3ebGFQSOmWijoT4HSMGMcgmB5qqFvI1RYaUKYSmD73D6ZicrJrhZts8CYoiWTVWfBXACzBe4KWTJtU20GKCkkxdmBlHDPg+IIXpjctbRGkKzCRC5XSODGAwJbNrMwF06cg1O3UMedJ9LBpDCQDTVzp4B0i4j4KKgBygI9jHwMFi/r7KmQWxDKKlfSQLSOas0zBoSag9dCMZXAT4PoJLWY//IZwboCRAey5XnHqmavXBHSVFR4KwaEPvE2JiMH5qjji/pOp1FhDMBVJXYoGhkxm81jZ8NcdmvRydSe0rM/27dVYD0MArW1cWmaDn9swztNBB/mvoYMAw0gumPBP0lPaT9fnx1/SoFxD8roAAxOSrW3BEbW1HBJwF8IkAnADgOwHiT1f0utg4QV+HxXwFa0dpKyybNrV/vt1Ey9K8AKSJKf0/GB2s5fYqm6UcRaROJMIHB44kRZmCs23dAFpjOBKxnQpZA65jxDrO+Vte11XpIW3VkIrWzCDdLuqoCxL3wUzYdGaV38EiNyo4g5IbrOoYSYQiYBkGjAcx8mAYcwkAFgH6gfUmXjByANgJadeAjItoNnXeB+ANm7NA0bGeE3tO5Y6tWRpvD0cwmAOyeK6XbsgKkdGOvPDehgALEhEiqSOkqoAAp3dgrz00ooAAxIZIqUroKKEBKN/bKcxMKKEBMiKSKlK4CCpDSjb3y3IQCChATIqkipauAAqR0Y688N6GAAsSESKpI6SqgACnd2CvPTSjw/7bmn6o8qtUUAAAAAElFTkSuQmCC")
        image_data = io.BytesIO(image_bytes)
        image = Image.open(image_data)
        icon = pystray.Icon("icon", image, "图标名称", menu)

        threading.Thread(target=icon.run, daemon=True).start()
        threading.Thread(target=self.init_capture, daemon=True).start()

        # 重新定义点击关闭按钮的处理
        self.window.protocol('WM_DELETE_WINDOW', self.on_exit)
        self.window.title('摄像壁纸')
        self.window.mainloop()


if __name__ == '__main__':
    window = Window()
    window.start()

2. 创建文件requirements.txt,文件内容

numpy==1.26.2
opencv-python==4.8.1.78
Pillow==10.1.0
pystray==0.19.5
pywin32==306
six==1.16.0

3. 安装依赖

pip install -r requirements.txt

4. 运行

双击main.pyw


防火布

你可能感兴趣的:(桌面壁纸,摄像头桌面壁纸)