python弹幕祝福
时间: 2023-11-21 18:58:41 浏览: 202
以下是一个简单的Python弹幕祝福程序,它可以在屏幕上显示随机的弹幕文字:
```python
import tkinter as tk
import random
class Barrage:
def __init__(self):
self.tk = tk.Tk()
self.tk.overrideredirect(True)
self.tk.attributes("-topmost", True)
self.tk.attributes("-transparentcolor", "white")
self.tk.geometry("+0+0")
self.canvas = tk.Canvas(self.tk, width=self.tk.winfo_screenwidth(), height=self.tk.winfo_screenheight(), bd=0, highlightthickness=0)
self.canvas.pack()
self.tk.update()
self.w = self.tk.winfo_screenwidth()
self.h = self.tk.winfo_screenheight()
self.x = str(random.randint(0, self.h))
self.y = str(random.randint(0, self.w))
self.tk.geometry("600x200+"+self.y+"+"+self.x)
self.canvas.create_text(100,80,text="祝福语:祝你生日快乐!",font=("Segoe UI Black",18))
self.barrage_text()
def barrage_text(self):
text_list=["∑(っ°Д°;)っ握抄","(*^▽^*)", "!!!∑(゚Д゚ノ)ノ","Σσ(・Д・;)我我我什么都没做!!!", "(づ ̄3 ̄)づ╭❤~","๑乛◡乛๑卡在了奇怪的地方"]
self.canvas.create_text(self.w, random.randint(0, self.h), text=random.choice(text_list), font=("Segoe UI Black",18), fill="white")
self.canvas.move(tk.ALL, -20, 0)
self.tk.update()
self.canvas.after(100, self.barrage_text)
barrage = Barrage()
barrage.tk.mainloop()
```
阅读全文