本文目录一览:
用chatgpt生成双色球选号工具
chatgpt对自然语句的理解实在是太强大了,直接提问“用pyside6写一个双色球选号工具”,它理解你想干什。直接可输出结果。关键是代码一字未改,可直接运行!
生成代码还有中文注释:
from PySide6.QtCore import Qtfrom PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButtonimport randomclass MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("双色球选号工具") self.setFixedSize(400, 300) # 创建主窗口部件 main_widget = QWidget(self) self.setCentralWidget(main_widget) # 创建布局 main_layout = QVBoxLayout() top_layout = QHBoxLayout() bottom_layout = QHBoxLayout() main_layout.addLayout(top_layout) main_layout.addLayout(bottom_layout) # 创建顶部部件 self_label = QLabel("红球:") top_layout.addWidget(self_label) self_numbers = [] for i in range(6): number_label = QLabel("") number_label.setFixedSize(30, 30) number_label.setAlignment(Qt.AlignCenter) number_label.setStyleSheet("border: 1px solid black") self_numbersend(number_label) top_layout.addWidget(number_label) self_label = QLabel("蓝球:") top_layout.addWidget(self_label) self_number = QLabel("") self_number.setFixedSize(30, 30) self_number.setAlignment(Qt.AlignCenter) self_number.setStyleSheet("border: 1px solid black") top_layout.addWidget(self_number) # 创建底部部件 self.generate_button = QPushButton("生成号码") self.generate_buttonednnect(self.generate_numbers) bottom_layout.addWidget(self.generate_button) self.clear_button = QPushButton("清空") self.clear_buttonednnect(self.clear_numbers) bottom_layout.addWidget(self.clear_button) # 设置主窗口部件的布局 main_widget.setLayout(main_layout) # 生成号码的方法 def generate_numbers(self): red_balls = random.sample(range(1, 34), 6) blue_ball = random.randint(1, 17) red_ballsrt() for i in range(6): self_numbers[i].setText(str(red_balls[i])) self_number.setText(str(blue_ball)) # 清空号码的方法 def clear_numbers(self): for i in range(6): self_numbers[i].setText("") self_number.setText("")if __name__ == "__main__": app = QApplication([]) window = MainWindow() window() app.exec_()