猫史档案馆


【Python作品分享】新的作品【作品秀】

用户:好想脱单好想脱单查看:0 回复:0 评论:0 创建时间:2023-01-09T19:26:09


【作品展示】

center_image

 

【作品介绍】

 

【作品源代码】

import tkinter as tk
import random
import threading  # 使用多线程
import time


def dow():
    color_list = ['red', 'green', 'blue', 'yellow', 'grey', 'brown', 'gold']
    font_list = ['黑体', '宋体', '仿宋', '微软雅黑',
                 '楷体', '隶书', '华文琥珀', '幼圆', '华文行楷', '新宋体']
    text_list = ['吴浩东是喵'
                 ]
    window = tk.Tk()
    width = window.winfo_screenwidth()
    height = window.winfo_screenheight()
    a = random.randrange(0, width)
    b = random.randrange(0, height)
    window.title('来自吴振南的祝福')
    window.geometry("280x100" + "+" + str(a) + "+" + str(b))
    tk.Label(window,
             text=random.sample(text_list, 1),  # 标签的文字
             bg=random.sample(color_list, 1),  # 背景颜色
             font=(random.sample(font_list, 1), 17),  # 字体和字体大小
             width=20, height=20  # 标签长宽
             ).pack()  # 固定窗口位置
    window.mainloop()


def bless(x):
    threads = []
    for i in range(x):  # 需要的弹框数量
        t = threading.Thread(target=dow)
        threads.append(t)
        time.sleep(0.0001)
        threads[i].start()


def main():
    num = int(input('请输入需要的祝福数量:'))
    bless(num)


if __name__ == '__main__':
    main()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页