import tkinter as tk
import random
import threading
import time
from PIL import Image,ImageTk

class MovingLabel(threading.Thread):
    def __init__(self,window,text):
        threading.Thread.__init__(self)
        self.text=text
        self.label=tk.Label(window,image=kuang,text=self.text,compound="center",font=("黑体",20),fg="white",width=190,height=45)
        self.label.place(x=800,y=random.randint(10,550))

    def run(self):
        x=800
        while x>-200:
            x-=2
            self.label.place(x=x)
            time.sleep(0.02)
        self.label.destroy()


def send():
    text=e1.get()
    m1=MovingLabel(window,text)
    m1.start()


window=tk.Tk()
window.geometry("1000x670")
window.resizable(0,0)
kuang=ImageTk.PhotoImage(file="kuang.png")
bg_image=Image.open("tv.png")
bg_image=ImageTk.PhotoImage(bg_image)
bg_label=tk.Label(window,image=bg_image)
bg_label.pack()
e1=tk.Entry(window,font=("黑体",20))
e1.place(x=280,y=620)
b1=tk.Button(window,text="发送弹幕",font=("黑体",20),command=send)
b1.place(x=580,y=613)
window.mainloop()