【Python】全站最简洁的抽奖软件

【Python】全站最简洁的抽奖软件

抽奖软件,号称全站最简洁!

用法如下:

1.打开“LotteryList.txt”文件,一行一行添加抽奖人名字

00b2b149e4162613

2.打开抽奖软件,点击“Start”按钮开始抽奖

849b10f725162812

3.点击“Stop”按钮停止抽奖

698dabad22163125

4.最后抽奖结果就会打印在控制台上

8b345e43e6163352

源代码如下:

import tkinter as tk  # Import the tkinter module for GUI
import random  # Import the random module for generating random numbers

class LotteryApp:
    def __init__(self):
        self.root = tk.Tk()  # Create a Tkinter root window
        self.root.title("Random Lottery")  # Set the title of the application window
        self.root.geometry("400x300+200+100")  # Set the size and position of the application window
        self.running = False  # Initialize the running state of the lottery

        # Create a label widget to display the selected name
        self.lbl1 = tk.Label(self.root, font=("Arial", 30), justify='left', width=10, height=2, bg='#BFEFFF')
        self.lbl1.place(x=90, y=50)

        btn_text = "Start"
        # Create a button widget to start/stop the lottery
        self.btn1 = tk.Button(self.root, text=btn_text, font=("Arial", 24), command=self.start_stop)
        self.btn1.place(x=120, y=180)

        self.root.resizable(False, False)  # Disable window resizing
    
    def start_stop(self):
        if self.running:  # If the lottery is running
            self.running = False  # Stop the lottery
            self.btn1['text'] = 'Start'  # Update the button text
            print(self.lbl1['text'])  # Print the selected name on the console
        else:  # If the lottery is not running
            self.running = True  # Start the lottery
            self.btn1['text'] = 'Stop'  # Update the button text
            self.scroll()  # Scroll the names

    def scroll(self):
        if self.running:
            xx = random.choice(a)  # Select a random name from the list
            yy = xx.strip()  # Remove leading/trailing whitespace
            self.lbl1['text'] = yy  # Update the label with the selected name
            self.lbl1.place(x=90, y=50)
            self.root.after(1, self.scroll)  # Schedule the next name scrolling

if __name__ == "__main__":
    lottery_app = LotteryApp()  # Create an instance of the LotteryApp class
    a = list(open("./LotteryList.txt", encoding="utf-8"))  # Read the names from the file
    lottery_app.root.mainloop()  # Start the Tkinter event loop

软件给大家打包好了,在下面:

 
抽奖软件.zip
zip文件
1.4K
© 版权声明
THE END
喜欢就支持一下吧
点赞41打赏 分享
评论 共2条

请登录后发表评论