让Ai给你写了一个复杂的
import random
import tkinter as tk
class CardPool:
def __init__(self):
网页链接 = {'SSR': 5, 'SR': 10, 'R': 30, 'N': 55}
def draw_card(self):
rand_num = random.randint(1, 100)
probability_sum = 0
for card, probability in self.cards.items():
probability_sum += probability
if rand_num <= probability_sum:
return card
def draw_card_text():
card_drawn = card_pool.draw_card()
output_text.set("你抽到了 {} 卡!".format(card_drawn))
def close_window():
root.destroy()
root = tk.Tk()
root.title("抽卡游戏")
# 固定窗口大小
root.resizable(width=False, height=False)
card_pool = CardPool()
title_label = tk.Label(root, text="欢迎来到抽卡游戏!按下抽卡按钮进行抽卡,按下退出按钮结束游戏。")
title_label.pack()
draw_button = tk.Button(root, text="抽卡", command=draw_card_text)
draw_button.pack()
exit_button = tk.Button(root, text="退出", command=close_window)
exit_button.pack()
output_text = tk.StringVar()
output_label = tk.Label(root, textvariable=output_text)
output_label.pack()
# 将窗口居中显示
window_width = 300
window_height = 200
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_coordinate = (screen_width - window_width) // 2
y_coordinate = (screen_height - window_height) // 2
root.geometry("+{}+{}".format(x_coordinate, y_coordinate))
root.mainloop()
打包成EXE可执行