日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python土味情话_Python 将土味情话语录设置为桌面壁纸

發(fā)布時(shí)間:2024/9/27 python 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python土味情话_Python 将土味情话语录设置为桌面壁纸 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文編寫(xiě)于 128 天前,最后修改于 128 天前,其中某些信息可能已經(jīng)過(guò)時(shí)。

41041-3yfokd0irbe.png

38220-tlrmwji3zwo.pngimport os

import tempfile

import time

import requests

import win32api

import win32con

import win32gui

from PIL import Image, ImageDraw, ImageFont

import random

def setWallPaper(pic):

key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)

win32api.RegSetValueEx(key, "WallpaperStyle", 0, win32con.REG_SZ, "2")# 2拉伸適應(yīng)桌面,0桌面居中

win32api.RegSetValueEx(key, "TileWallpaper", 0, win32con.REG_SZ, "0")

win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, pic, 1 + 2)

print('成功應(yīng)用桌面壁紙')

def love():

url = r'https://api.vvhan.com/api/love'

res = requests.get(url).text

content = "『{}』".format(res)

return content

def love2():

url = r'https://api.lovelive.tools/api/SweetNothings/WebSite'

res = requests.get(url).text

content = "『{}』".format(res)

return content

def hitokoto():

url = 'https://v1.hitokoto.cn/'

res = requests.get(url).json()

hitokoto = res['hitokoto'].strip('。')

from_where = res['from']

from_who = res['from_who']

content = "『{}』".format(hitokoto)

return content

def word():

global word_type

if word_type == '0':

return hitokoto()

elif word_type == '1':

return random.choice([love(), love2()])

def jpg(path):

if not os.path.exists(path):

url = 'https://cn-south-227-storage-hitokoto-19627663.oss.dogecdn.com/pic/qf3cu.jpg'

content = requests.get(url).content

with open(path, 'wb+') as f:

f.write(content)

# 語(yǔ)錄類(lèi)型

word_type = 0

# 臨時(shí)目錄

root_path = tempfile.gettempdir()

# 背景圖片路徑

bgfile = os.path.join(root_path, "bg.jpg")

# 最終的壁紙圖片路徑

wallfile = os.path.join(root_path, "wall.jpg")

def main():

# 下載背景圖

jpg(bgfile)

# 打開(kāi)背景圖

img = Image.open(bgfile)

# 創(chuàng)建空白圖

d = ImageDraw.Draw(img)

# 設(shè)置字體

font = ImageFont.truetype("simhei.ttf", 60, encoding="utf-8")

width, height = img.size

length = 99

one_word = ""

# 確保語(yǔ)錄不超過(guò)壁紙寬度

while (length > width//60):

# 獲取語(yǔ)錄

one_word = word()

length = len(one_word)

time.sleep(1)

print(one_word)

# 語(yǔ)錄添加到圖片

d.text((width / 2 - 30 * (len(one_word)), height / 2 - 240), one_word, font=font, fill=(80, 80, 80, 128))

# 報(bào)錯(cuò)圖片

img.save(wallfile)

# 關(guān)閉流

img.close()

# 設(shè)置壁紙

setWallPaper(wallfile)

# 刪除壁紙圖片

os.unlink(wallfile)

# 刪除背景圖片

# os.unlink(bgfile)

if __name__ == '__main__':

word_type = input('>> 類(lèi)型(0:一言; 1:情話):').strip()

while True:

main()

time.sleep(5)

總結(jié)

以上是生活随笔為你收集整理的python土味情话_Python 将土味情话语录设置为桌面壁纸的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。