请把这段代码生成一个GUI,在GUI里面,每次生成5组双色球号码,设置一个更换随机号码的按钮,退出按钮,显示当前的时间年,月,日,小时,分钏,秒。
时间: 2024-06-12 07:06:27 浏览: 37
抱歉,作为AI语言模型,我无法生成GUI界面。但我可以提供Python代码示例,您可以在此基础上自己设计GUI界面。具体代码如下:
```python
import random
import tkinter as tk
import time
class DoubleColorBallGenerator:
def __init__(self):
self.numbers = list(range(1, 34))
self.balls = list(range(1, 17))
def generate(self):
red_balls = random.sample(self.numbers, 5)
red_balls.sort()
blue_ball = random.choice(self.balls)
return red_balls, blue_ball
class App:
def __init__(self, master):
self.generator = DoubleColorBallGenerator()
self.red_balls_var = tk.StringVar()
self.blue_ball_var = tk.StringVar()
self.time_var = tk.StringVar()
self.time_var.set(self.get_current_time())
self.red_balls_label = tk.Label(master, textvariable=self.red_balls_var, font=('Arial', 16))
self.blue_ball_label = tk.Label(master, textvariable=self.blue_ball_var, font=('Arial', 16))
self.time_label = tk.Label(master, textvariable=self.time_var, font=('Arial', 12))
self.generate_button = tk.Button(master, text='生成', command=self.generate)
self.quit_button = tk.Button(master, text='退出', command=master.quit)
self.change_button = tk.Button(master, text='换一组', command=self.generate)
self.red_balls_label.pack()
self.blue_ball_label.pack()
self.time_label.pack()
self.generate_button.pack(side='left', padx=10)
self.change_button.pack(side='left', padx=10)
self.quit_button.pack(side='left', padx=10)
def generate(self):
red_balls, blue_ball = self.generator.generate()
self.red_balls_var.set('红球:' + ' '.join(str(ball) for ball in red_balls))
self.blue_ball_var.set('蓝球:' + str(blue_ball))
self.time_var.set(self.get_current_time())
def get_current_time(self):
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
root = tk.Tk()
root.title('双色球号码生成器')
app = App(root)
root.mainloop()
```
阅读全文