最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Python編寫一個桌面便簽應(yīng)用

 更新時間:2023年06月27日 08:57:38   作者:TANKING  
ChatGPT的編程能力也不差,本文將一步一步提出要求,讓ChatGPT根據(jù)我們的要求,編寫出一個可用的,可打包運(yùn)行的桌面便簽,感興趣的可以了解一下

ChatGPT的編程能力也不差,本次我就一步一步提要求,讓ChatGPT根據(jù)我的要求,編寫出一個可用的,可打包運(yùn)行的桌面便簽。

代碼

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QAction, QSystemTrayIcon, QMessageBox, QTextEdit
from PyQt5.QtCore import Qt, QPoint, QRect, QSize
from PyQt5.QtGui import QPainter, QColor, QBrush, QPen, QIcon, QFont, QCursor

class RoundedWindow(QMainWindow):
    def __init__(self, radius):
        super().__init__()
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setGeometry(700, 400, 400, 300)
        self.radius = radius
        self.draggable = False
        self.drag_position = QPoint()
        self.default_font_size = 13
        self.current_font_size = self.default_font_size
        self.resizing = False

        # 創(chuàng)建系統(tǒng)托盤圖標(biāo)
        self.tray_icon = QSystemTrayIcon(self)
        self.tray_icon.setIcon(QIcon("noteIcon.png"))
        self.tray_icon.activated.connect(self.handleTrayIconActivated)

        # 創(chuàng)建鼠標(biāo)右鍵菜單
        self.tray_menu = QMenu(self)
        exit_action = QAction("退出", self)
        exit_action.triggered.connect(QApplication.instance().quit)
        self.tray_menu.addAction(exit_action)
        self.tray_icon.setContextMenu(self.tray_menu)

        # 創(chuàng)建文本編輯框
        self.text_edit = QTextEdit(self)
        self.text_edit.setGeometry(10, 40, self.width() - 20, self.height() - 50)
        self.text_edit.setStyleSheet("background-color: transparent; border: none; color: white;")
        self.text_edit.setFont(QFont("Arial", self.current_font_size))
        self.text_edit.textChanged.connect(self.saveTextToFile)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(QColor(0, 0, 0, 150))  # 設(shè)置半透明背景顏色
        painter.drawRoundedRect(self.rect(), self.radius, self.radius)

        # 繪制紅色關(guān)閉按鈕
        close_button = QRect(10, 10, 20, 20)
        painter.setBrush(QColor(255, 0, 0))
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(close_button)

        # 繪制黃色最小化按鈕
        minimize_button = QRect(40, 10, 20, 20)
        painter.setBrush(QColor(255, 255, 0))
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(minimize_button)

        # 繪制灰色最大化按鈕
        maximize_button = QRect(70, 10, 20, 20)
        painter.setBrush(QColor(128, 128, 128))
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(maximize_button)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.draggable = True
            self.drag_position = event.globalPos() - self.frameGeometry().topLeft()
            event.accept()

            # 判斷點(diǎn)擊的按鈕
            pos = event.pos()
            if QRect(10, 10, 20, 20).contains(pos):
                self.close()  # 關(guān)閉當(dāng)前窗口
            elif QRect(40, 10, 20, 20).contains(pos):
                self.hide()  # 最小化當(dāng)前窗口

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton and self.draggable:
            self.move(event.globalPos() - self.drag_position)
            event.accept()

        # 檢查是否在窗口右下角,設(shè)置鼠標(biāo)形狀
        if self.isInBottomRightCorner(event.pos()):
            self.setCursor(Qt.SizeFDiagCursor)
        else:
            self.setCursor(Qt.ArrowCursor)

        # 檢查是否正在調(diào)整窗口大小
        if self.resizing:
            self.resizeWindow(event.globalPos())

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.draggable = False
            self.resizing = False
            event.accept()

    def handleTrayIconActivated(self, reason):
        if reason == QSystemTrayIcon.Trigger:
            self.showNormal()  # 點(diǎn)擊托盤圖標(biāo)恢復(fù)窗口顯示

    def closeEvent(self, event):
        self.hide()  # 窗口關(guān)閉時隱藏而不是退出應(yīng)用程序
        self.tray_icon.show()  # 顯示系統(tǒng)托盤圖標(biāo)
        event.ignore()  # 忽略窗口關(guān)閉事件

    def saveTextToFile(self):
        text = self.text_edit.toPlainText()
        with open("bianqian.txt", "w") as file:
            file.write(text)

    def isInBottomRightCorner(self, pos):
        window_rect = self.rect()
        corner_rect = QRect(window_rect.bottomRight() - QPoint(20, 20), QSize(20, 20))
        return corner_rect.contains(pos)

    def resizeWindow(self, pos):
        new_size = QSize(pos.x() - self.geometry().left(), pos.y() - self.geometry().top())
        self.resize(new_size)

    def wheelEvent(self, event):
        if event.modifiers() == Qt.ControlModifier:
            delta = event.angleDelta().y()
            if delta > 0:
                self.increaseFontSize()
            else:
                self.decreaseFontSize()

    def increaseFontSize(self):
        self.current_font_size += 1
        self.text_edit.setFont(QFont("Arial", self.current_font_size))

    def decreaseFontSize(self):
        if self.current_font_size > 1:
            self.current_font_size -= 1
            self.text_edit.setFont(QFont("Arial", self.current_font_size))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    radius = 15  # 修改圓角的值
    window = RoundedWindow(radius)
    window.show()

    # 調(diào)試:檢查系統(tǒng)托盤是否可用
    if not QSystemTrayIcon.isSystemTrayAvailable():
        QMessageBox.critical(None, "錯誤", "系統(tǒng)托盤不可用!")
        sys.exit(1)

    # 調(diào)試:檢查圖標(biāo)是否加載成功
    if not window.tray_icon.isSystemTrayAvailable():
        QMessageBox.critical(None, "錯誤", "無法加載系統(tǒng)托盤圖標(biāo)!")
        sys.exit(1)

    window.tray_icon.show()
    sys.exit(app.exec_())

運(yùn)行

便簽屬性

1、半透明、圓角、最小化、系統(tǒng)托盤

2、按住Ctrl不放滾動鼠標(biāo)可改變文字大小

3、系統(tǒng)托盤鼠標(biāo)右鍵完全退出

4、便簽輸入的文字實(shí)時更新至bianqian.txt

打包成exe

這么點(diǎn)東西打包成exe居然有34.9M這么大!這絕對不是Python的問題,是我技術(shù)的問題。

以上就是使用Python編寫一個桌面便簽應(yīng)用的詳細(xì)內(nèi)容,更多關(guān)于Python桌面便簽的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

永宁县| 明光市| 黑河市| 敦化市| 夏河县| 毕节市| 屯昌县| 扶余县| 海南省| 彭山县| 漾濞| 竹北市| 元阳县| 宝兴县| 通海县| 瓮安县| 庐江县| 类乌齐县| 日喀则市| 延边| 衡阳市| 保山市| 高淳县| 贵定县| 邓州市| 洪湖市| 布尔津县| 河北省| 宜宾市| 金昌市| 葫芦岛市| 东至县| 大田县| 聂荣县| 无棣县| 景泰县| 襄城县| 新密市| 阳信县| 元谋县| 新野县|