目录
需求
通过python代码,实现双色球彩票选号,模拟摇奖,开奖,显示中奖情况
实现效果
代码实现
import tkinter as tk
from tkinter import messagebox
import random
class DoubleColorBallApp:
def __init__(self, root):
self.root = root
self.root.title("双色球彩票程序")
self.red_balls = []
self.blue_ball = None
self.drawn_red_balls = []
self.drawn_blue_ball = None
self.bet_frames = []
self.max_bets = 5
self.current_bet = 0
self.create_widgets()
def create_widgets(self):
# 创建红球选择框
self.red_frame = tk.Frame(self.root)
self.red_frame.pack(pady=10)
self.red_vars = []
for i in range(1, 34):
var = tk.IntVar()
chk = tk.Checkbutton(self.red_frame, text=f"{i:02}", variable=var)
chk.grid(row=(i - 1) // 10, column=(i - 1) % 10)
self.red_vars.append(var)
# 创建蓝球选择框
self.blue_frame = tk.Frame(self.root)
self.blue_frame.pack(pady=10)
self.blue_var = tk.IntVar()
for i in range(1, 17):
rb = tk.Radiobutton(self.blue_frame, text=f"{i:02}", variable=self.blue_var, value=i)
rb.grid(row=0, column=i - 1)
# 创建按钮
self.button_frame = tk.Frame(self.root)
self.button_frame.pack(pady=10)
self.add_bet_butto