亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用PyQt5編寫(xiě)一個(gè)簡(jiǎn)單的取色器

 更新時(shí)間:2025年01月15日 10:30:49   作者:阿九筒  
這篇文章主要為大家介紹了PyQt5搭建的一個(gè)取色器,一共寫(xiě)了兩款應(yīng)用,一款使用快捷鍵捕獲鼠標(biāo)附近圖像的RGB和16進(jìn)制顏色編碼,一款跟隨鼠標(biāo)刷新圖像的RGB和16進(jìn)制顏色編碼,希望對(duì)大家有所幫助

PyQt5搭建的一個(gè)取色器,一共寫(xiě)了兩款應(yīng)用,一款使用快捷鍵捕獲鼠標(biāo)附近圖像的RGB和16進(jìn)制顏色編碼,一款跟隨鼠標(biāo)刷新圖像的RGB和16進(jìn)制顏色編碼。桌面應(yīng)用程序的背景色切換也可以參考此程序。

源程序的git地址: gitee.com/mtoooo/color_picker

打包的exe下載鏈接: gitee.com/mtoooo/color_picker

取色器1

源代碼參考main.py,也可以點(diǎn)擊頂部exe鏈接下載取色器.exe文件直接使用,取色快捷鍵Shift+A,應(yīng)用程序會(huì)顯示RGB和16進(jìn)制顏色編碼。

源程序初始化

pip install PyQt5==5.15.10

程序啟動(dòng)

python main.py

取色快捷鍵Shift+A

交互效果

main.py

import sys
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QColor, QPixmap, QCursor, QPainter, QPen, QBrush
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QHBoxLayout

class ColorPickerApp(QWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Color Picker")
        self.setGeometry(100, 100, 300, 200)

        # 創(chuàng)建標(biāo)簽,用于顯示 RGB 和 16 進(jìn)制顏色
        self.rgb_hex_label = QLabel("RGB: None\nHex: None", self)

        # 設(shè)置標(biāo)簽樣式和大小
        self.rgb_hex_label.setFixedSize(150, 50)  # 設(shè)置固定大小 100x50
        self.rgb_hex_label.setStyleSheet("font-size: 12px; padding: 5px; border-radius: 5px; background-color: white; border: 1px solid black;")

        # 設(shè)置布局,使用 QHBoxLayout 和 QVBoxLayout 居中顯示標(biāo)簽
        layout = QVBoxLayout(self)
        layout.setAlignment(Qt.AlignCenter)  # 設(shè)置垂直布局居中
        layout.addWidget(self.rgb_hex_label)
        self.setLayout(layout)

        # 定時(shí)器用于定時(shí)獲取顏色信息
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_color)
        self.timer.start(100)  # 每100毫秒更新一次

        # 用來(lái)存儲(chǔ)背景顏色
        self.bg_color = QColor(255, 255, 255)  # 默認(rèn)背景為白色

    def update_color(self):
        # 獲取鼠標(biāo)位置
        cursor_pos = QCursor.pos()

        # 獲取屏幕截圖并獲取當(dāng)前鼠標(biāo)位置的顏色
        screen = QApplication.primaryScreen()
        pixmap = screen.grabWindow(0)
        color = QColor(pixmap.toImage().pixel(cursor_pos))

        # 獲取 RGB 和 16 進(jìn)制顏色值
        rgb = color.getRgb()
        hex_color = color.name()

        # 更新標(biāo)簽顯示顏色信息
        self.rgb_hex_label.setText(f"RGB: {rgb[0]}, {rgb[1]}, {rgb[2]}\nHex: {hex_color}")

        # 改變窗口背景色
        self.bg_color = color

        # 刷新窗口
        self.update()

    def paintEvent(self, event):
        # 繪制背景顏色
        painter = QPainter(self)
        painter.setBrush(QBrush(self.bg_color))
        painter.setPen(Qt.NoPen)
        painter.drawRect(self.rect())  # 填充整個(gè)窗口背景

        painter.end()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = ColorPickerApp()
    window.show()
    sys.exit(app.exec_())

取色器2

源代碼參考main2.py, 也可以下載取色器2.exe文件直接使用,無(wú)需快捷鍵運(yùn)行即可使用,應(yīng)用程序會(huì)顯示RGB和16進(jìn)制顏色編碼。

- 源程序初始化

pip install PyQt5==5.15.10

程序啟動(dòng)

python main2.py

交互效果

main2.py

import sys
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QColor, QPixmap, QCursor, QPainter, QPen, QBrush
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QHBoxLayout

class ColorPickerApp(QWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Color Picker")
        self.setGeometry(100, 100, 300, 200)

        # 創(chuàng)建標(biāo)簽,用于顯示 RGB 和 16 進(jìn)制顏色
        self.rgb_hex_label = QLabel("RGB: None\nHex: None", self)

        # 設(shè)置標(biāo)簽樣式和大小
        self.rgb_hex_label.setFixedSize(150, 50)  # 設(shè)置固定大小 100x50
        self.rgb_hex_label.setStyleSheet("font-size: 12px; padding: 5px; border-radius: 5px; background-color: white; border: 1px solid black;")

        # 設(shè)置布局,使用 QHBoxLayout 和 QVBoxLayout 居中顯示標(biāo)簽
        layout = QVBoxLayout(self)
        layout.setAlignment(Qt.AlignCenter)  # 設(shè)置垂直布局居中
        layout.addWidget(self.rgb_hex_label)
        self.setLayout(layout)

        # 定時(shí)器用于定時(shí)獲取顏色信息
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_color)
        self.timer.start(100)  # 每100毫秒更新一次

        # 用來(lái)存儲(chǔ)背景顏色
        self.bg_color = QColor(255, 255, 255)  # 默認(rèn)背景為白色

    def update_color(self):
        # 獲取鼠標(biāo)位置
        cursor_pos = QCursor.pos()

        # 獲取屏幕截圖并獲取當(dāng)前鼠標(biāo)位置的顏色
        screen = QApplication.primaryScreen()
        pixmap = screen.grabWindow(0)
        color = QColor(pixmap.toImage().pixel(cursor_pos))

        # 獲取 RGB 和 16 進(jìn)制顏色值
        rgb = color.getRgb()
        hex_color = color.name()

        # 更新標(biāo)簽顯示顏色信息
        self.rgb_hex_label.setText(f"RGB: {rgb[0]}, {rgb[1]}, {rgb[2]}\nHex: {hex_color}")

        # 改變窗口背景色
        self.bg_color = color

        # 刷新窗口
        self.update()

    def paintEvent(self, event):
        # 繪制背景顏色
        painter = QPainter(self)
        painter.setBrush(QBrush(self.bg_color))
        painter.setPen(Qt.NoPen)
        painter.drawRect(self.rect())  # 填充整個(gè)窗口背景

        painter.end()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = ColorPickerApp()
    window.show()
    sys.exit(app.exec_())

到此這篇關(guān)于使用PyQt5編寫(xiě)一個(gè)簡(jiǎn)單的取色器的文章就介紹到這了,更多相關(guān)PyQt5取色器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python3中正則模塊re.compile、re.match及re.search函數(shù)用法詳解

    Python3中正則模塊re.compile、re.match及re.search函數(shù)用法詳解

    這篇文章主要介紹了Python3中正則模塊re.compile、re.match及re.search函數(shù)用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了re模塊 中re.compile、re.match及re.search函數(shù)的功能、參數(shù)、具體使用技巧與注意事項(xiàng),需要的朋友可以參考下
    2018-06-06
  • pytorch中的reshape()、view()、nn.flatten()和flatten()使用

    pytorch中的reshape()、view()、nn.flatten()和flatten()使用

    這篇文章主要介紹了pytorch中的reshape()、view()、nn.flatten()和flatten()使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • Python 3.8正式發(fā)布,來(lái)嘗鮮這些新特性吧

    Python 3.8正式發(fā)布,來(lái)嘗鮮這些新特性吧

    今天 Python3.8 發(fā)布啦,它是 Python2 終結(jié)前最后一個(gè)大版本,我們一起看看這個(gè)版本都添加了那些新功能和特性
    2019-10-10
  • python腳本框架webpy的url映射詳解

    python腳本框架webpy的url映射詳解

    這篇文章主要為大家介紹了python腳本框架web.py的url映射的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2021-11-11
  • Python技法-序列拆分詳解

    Python技法-序列拆分詳解

    Python中的任何序列(可迭代的對(duì)象)都可以通過(guò)賦值操作進(jìn)行拆分,包括但不限于元組、列表、字符串、文件、迭代器、生成器等。
    2021-10-10
  • python利用urllib實(shí)現(xiàn)爬取京東網(wǎng)站商品圖片的爬蟲(chóng)實(shí)例

    python利用urllib實(shí)現(xiàn)爬取京東網(wǎng)站商品圖片的爬蟲(chóng)實(shí)例

    下面小編就為大家?guī)?lái)一篇python利用urllib實(shí)現(xiàn)爬取京東網(wǎng)站商品圖片的爬蟲(chóng)實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • python使用PIL模塊實(shí)現(xiàn)給圖片打水印的方法

    python使用PIL模塊實(shí)現(xiàn)給圖片打水印的方法

    這篇文章主要介紹了python使用PIL模塊實(shí)現(xiàn)給圖片打水印的方法,涉及使用PIL模塊操作圖片的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • Python利用capstone實(shí)現(xiàn)反匯編

    Python利用capstone實(shí)現(xiàn)反匯編

    Capstone是一個(gè)輕量級(jí)的多平臺(tái)、多架構(gòu)的反匯編框架,該模塊支持目前所有通用操作系統(tǒng),反匯編架構(gòu)幾乎全部支持。本文就將利用他實(shí)現(xiàn)反匯編,感興趣的可以了解下
    2022-04-04
  • Pandas缺失值填充 df.fillna()的實(shí)現(xiàn)

    Pandas缺失值填充 df.fillna()的實(shí)現(xiàn)

    本文主要介紹了Pandas缺失值填充 df.fillna()的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • 使用Python程序抓取新浪在國(guó)內(nèi)的所有IP的教程

    使用Python程序抓取新浪在國(guó)內(nèi)的所有IP的教程

    這篇文章主要介紹了使用Python程序抓取新浪在國(guó)內(nèi)的所有IP的教程,作為Python網(wǎng)絡(luò)編程中獲取IP的一個(gè)小實(shí)踐,需要的朋友可以參考下
    2015-05-05

最新評(píng)論