The New Year has not yet arrived, but you have to prepare, and learn about the New Year greeting pop-up.

" New Year's greetings pop-up window, learn about it "

I remember that I posted a blessing pop-up article before, and some people complained that the article was published late and it was published after the holiday. It was a bit slow and should be published in advance. For this request, I will certainly satisfy you. This is not about Christmas, New Year's Day, Chinese New Year, Lantern Festival, all the bullet frames will be served together, plus the sliding bullet frame, to ensure your satisfaction.

As the saying goes, it is better to teach people how to fish than to teach people how to fish. This time I will explain clearly how to make bullet frames. Then let everyone make the bullet frame they want by themselves.

01—Code implementation

The main module used is tkinter, which is a built-in module of python, which is easy to learn. Each line is commented: the following is the way to implement the Christmas pop-up window.

import tkinter as tk
import random
import threading
import time

def window(a):
    window = tk.Tk()#实例化对象。
    window.overrideredirect(True)#设置关闭窗口按钮是否显示
    width = window.winfo_screenwidth()#获取窗口长宽
    height = window.winfo_screenheight()
    x = random.randrange(0, width)#获取屏幕长高
    y = random.randrange(0, height/2)
    tk.Label(window,
             text=a,  # 标签的文字
             bg='green',  # 背景颜色
             font=('楷体', 17),  # 字体和字体大小
             ).pack()  # 固定窗口位置
    for i in range(width-300):#实现移动窗口
        if x+i==width-300:
            window.destroy()#关闭窗口
            return
        window.attributes("-alpha",0.5)#设置窗口透明度
        window.geometry("150x30" + "+" + str(x+i*2) + "+" + str(y))#移动窗口位置
        window.update()#刷新窗口位置
    window.mainloop()
threads = []
list1=["圣诞快乐"]#需要的祝福信息。
for i in range(9):  # 需要的弹框数量
    t = threading.Thread(target=window,args=(list1[0],))
    threads.append(t)#将函数假如到线程中
    time.sleep(0.1)#加上停顿时间,防止太快,卡死。
    threads[i].start()#启动线程

 

Packaging, the code has been written, but it is just a bunch of code, if you need to run, you need to install the python environment, what should I do?

We need to package them, we need to use the module pyinstaller

pip install PyInstaller

安装成功之后,找到我们需要的文件,使用命令

pyinstall -w -F +文件名称

-F 表示生成单个可执行文件

-w 表示去掉控制台窗口,这在GUI界面时非常有用。

Then we can find the exe we generated in the dist under the two newly generated folders. Isn’t it amazing?

 

02—Extension

The Christmas blessings pop-up window can already be realized, and so on, we can change the blessings, such as Happy Chinese New Year, Happy New Year's Day, Happy Lantern Festival, Happy Qixi Festival; what are you waiting for, what are you afraid of with the code, give others a surprise Have a hi pop-up window!

All kinds of pop-up windows have been packed for everyone, the backstage reply, " pop-up windows ", get your gift package!

 

related suggestion:

How to automatically send text messages to his girlfriend

You can control the computer by sending commands through your mobile phone. Check it out!

Build your own voice chat robot

 

Like to remember to follow us!

 

Guess you like

Origin blog.csdn.net/qq_39046854/article/details/84995066