用ai写个番茄钟并打包成exe

工具:cursor
prompt:用pyqt帮我写个番茄钟
然后ai就开始写了

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QHBoxLayout, QLCDNumber
from PyQt5.QtCore import QTimer, Qt

class TomatoClock(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # Create labels
        self.timer_label = QLabel('25:00')
        self.timer_label.setAlignment(Qt.AlignCenter)
        self.timer_label.setStyleSheet('font-size: 80pt')
        self.status_label = QLabel('Work')
        self.status_label.setStyleSheet('color: red')

        # Create buttons
        self.start_button = QPushButton('Start')
        self.stop_button = QPushButton('Stop')
        self.reset_button = QPushButton('Reset')

        # Create timer
        self.timer = QTimer()
        self.timer.setInterval(1000)
        self.timer.timeout.connect(self.update_timer)

        # Create LCD number
        self.lcd = QLCDNumber()
        self.lcd.setDigitCount(2)
        self.lcd.display(25)

        # Create layouts
        vbox = QVBoxLayout()
        hbox = QHBoxLayout()

        # Add widgets to layouts
        vbox.addWidget(self.timer_label)
        vbox.addWidget(self.status_label)
        vbox.addWidget(self.lcd)
        hbox.addWidget(self.start_button)
        hbox.addWidget(self.stop_button)
        hbox.addWidget(self.reset_button)
        vbox.addLayout(hbox)

        # Set layout
        self.setLayout(vbox)

        # Set window properties
        self.setWindowTitle('Tomato Clock')
        self.setGeometry(100, 100, 300, 200)

        # Connect buttons to functions
        self.start_button.clicked.connect(self.start_timer)
        self.stop_button.clicked.connect(self.stop_timer)
        self.reset_button.clicked.connect(self.reset_timer)

    def start_timer(self):
        self.timer.start()

    def stop_timer(self):
        self.timer.stop()

    def reset_timer(self):
        self.timer.stop()
        self.timer_label.setText('25:00')
        self.status_label.setText('Work')
        self.status_label.setStyleSheet('color: red')
        self.lcd.display(25)

    def update_timer(self):
        time_left = self.timer_label.text()
        minutes, seconds = time_left.split(':')
        if int(seconds) > 0:
            seconds = str(int(seconds) - 1)
        elif int(minutes) > 0:
            minutes = str(int(minutes) - 1)
            seconds = '59'
        else:
            self.timer.stop()
            if self.status_label.text() == 'Work':
                self.status_label.setText('Break')
                self.status_label.setStyleSheet('color: green')
                self.timer_label.setText('05:00')
                self.lcd.display(5)
            else:
                self.status_label.setText('Work')
                self.status_label.setStyleSheet('color: red')
                self.timer_label.setText('25:00')
                self.lcd.display(25)
        self.timer_label.setText(f'{minutes.zfill(2)}:{seconds.zfill(2)}')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    clock = TomatoClock()
    clock.show()
    sys.exit(app.exec_())


最后打包文件,
1 安装PyInstaller库:可以使用pip安装PyInstaller库,命令为pip install pyinstaller

  1. 打开命令行窗口并导航到TomatoClock应用程序的目录。

  2. 运行以下命令将应用程序打包成单个可执行文件:

pyinstaller --onefile --noconsole main.py

这将在dist文件夹中创建一个可执行文件,而不会弹出命令行窗口。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鸭梨山大哎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值