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

Python結(jié)合PyQt5模擬實(shí)現(xiàn)微信程序聊天功能

 更新時(shí)間:2025年11月24日 09:29:15   作者:熊貓_豆豆  
這篇文章主要為大家詳細(xì)介紹了Python如何結(jié)合PyQt5模擬實(shí)現(xiàn)微信程序聊天功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

本文介紹了一個(gè)基于PyQt5的微信界面克隆實(shí)現(xiàn)。該程序創(chuàng)建了一個(gè)包含側(cè)邊欄和聊天區(qū)域的主窗口,模擬了微信的基本UI元素和交互功能。側(cè)邊欄包含用戶(hù)信息、搜索框、功能按鈕和聊天列表,聊天區(qū)域則實(shí)現(xiàn)了消息顯示和輸入功能。程序支持發(fā)送文本消息、表情符號(hào)和文件,并模擬了自動(dòng)回復(fù)功能。界面設(shè)計(jì)遵循微信風(fēng)格,包括圓形頭像、氣泡消息框和綠色主題色。該實(shí)現(xiàn)展示了如何使用PyQt5構(gòu)建復(fù)雜的GUI應(yīng)用程序,涵蓋了布局管理、樣式定制、事件處理和組件交互等關(guān)鍵技術(shù)。

效果圖

完整代碼 

import sys
import os
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, 
                            QHBoxLayout, QListWidget, QListWidgetItem, QLineEdit,
                            QTextEdit, QPushButton, QLabel, QSplitter, QFrame,
                            QScrollArea, QComboBox, QMenu, QAction, QSizePolicy,
                            QMessageBox, QFileDialog, QGridLayout)
from PyQt5.QtGui import (QPixmap, QIcon, QFont, QColor, QPainter, QBrush, QPen,
                         QPalette, QCursor)
from PyQt5.QtCore import Qt, QSize, QPoint, pyqtSignal, QRect, QTimer, QEvent

# 移除matplotlib依賴(lài),因?yàn)槲覀儾恍枰?
# 移除以下導(dǎo)入:
# import matplotlib
# matplotlib.use('Agg')
# import matplotlib.pyplot as plt
# plt.rcParams["font.family"] = ["SimHei", "WenQuanYi Micro Hei", "Heiti TC"]

# 直接在PyQt5中設(shè)置字體支持中文
QFont.insertSubstitutions("SimHei", ["SimHei", "WenQuanYi Micro Hei", "Heiti TC"])

# 主應(yīng)用程序類(lèi)
class WeChatClone(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
    
    def initUI(self):
        # 全局樣式優(yōu)化
        # 設(shè)置窗口標(biāo)題和大小
        self.setWindowTitle('微信')
        self.setGeometry(300, 300, 1200, 800)
        
        # 設(shè)置窗口樣式 - 微信風(fēng)格
        self.setStyleSheet("""
            QMainWindow {
                background-color: #f5f5f5;
            }
            QSplitter::handle { 
                background-color: #e0e0e0; 
            }
        """)
        
        # 創(chuàng)建中心窗口部件
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        
        # 創(chuàng)建主布局
        main_layout = QHBoxLayout(central_widget)
        main_layout.setContentsMargins(0, 0, 0, 0)
        main_layout.setSpacing(0)
        
        # 創(chuàng)建分割器來(lái)分隔側(cè)邊欄和聊天區(qū)域
        splitter = QSplitter(Qt.Horizontal)
        splitter.setHandleWidth(1)
        splitter.setStyleSheet("QSplitter::handle { background-color: #e0e0e0; }")
        
        # 創(chuàng)建側(cè)邊欄
        self.create_sidebar(splitter)
        
        # 創(chuàng)建聊天區(qū)域
        self.create_chat_area(splitter)
        
        # 設(shè)置分割器的初始大小
        splitter.setSizes([300, 900])
        
        # 限制最小寬度
        splitter.setChildrenCollapsible(False)
        
        # 將分割器添加到主布局
        main_layout.addWidget(splitter)
        
    def create_sidebar(self, parent):
        # 創(chuàng)建側(cè)邊欄框架
        sidebar = QWidget()
        sidebar.setStyleSheet("background-color: white;")
        sidebar_layout = QVBoxLayout(sidebar)
        sidebar_layout.setContentsMargins(0, 0, 0, 0)
        sidebar_layout.setSpacing(0)
        
        # 創(chuàng)建頂部用戶(hù)信息區(qū)域
        user_info_widget = QWidget()
        user_info_widget.setStyleSheet("background-color: white; border-bottom: 1px solid #e0e0e0;")
        user_info_layout = QHBoxLayout(user_info_widget)
        user_info_layout.setContentsMargins(15, 10, 10, 10)
        
        # 用戶(hù)頭像 - 圓形
        self.avatar_label = QLabel()
        avatar_pixmap = QPixmap(50, 50)
        avatar_pixmap.fill(QColor(100, 181, 246))
        # 創(chuàng)建圓形頭像
        painter = QPainter(avatar_pixmap)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(QBrush(QColor(100, 181, 246)))
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(0, 0, 50, 50)
        painter.end()
        
        self.avatar_label.setPixmap(avatar_pixmap)
        self.avatar_label.setFixedSize(50, 50)
        self.avatar_label.setScaledContents(True)
        
        # 用戶(hù)名
        self.username_label = QLabel('我')
        self.username_label.setFont(QFont('SimHei', 12, QFont.Bold))
        
        # 更多按鈕
        more_btn = QPushButton()
        more_btn.setText('?')
        more_btn.setFont(QFont('SimHei', 14))
        more_btn.setFixedSize(30, 30)
        more_btn.setStyleSheet("""
            QPushButton {
                border: none;
                background-color: transparent;
                color: #666;
            }
            QPushButton:hover {
                background-color: #f0f0f0;
                border-radius: 15px;
            }
        """)
        
        user_info_layout.addWidget(self.avatar_label)
        user_info_layout.addWidget(self.username_label, 0, Qt.AlignVCenter)
        user_info_layout.addStretch()
        user_info_layout.addWidget(more_btn)
        
        # 創(chuàng)建搜索框
        search_layout = QHBoxLayout()
        search_layout.setContentsMargins(15, 10, 15, 10)
        
        # 搜索容器
        search_container = QWidget()
        search_container.setStyleSheet("background-color: #f0f0f0; border-radius: 18px;")
        search_container_layout = QHBoxLayout(search_container)
        search_container_layout.setContentsMargins(10, 6, 10, 6)
        
        search_icon = QLabel()
        search_icon.setText('??')
        search_icon.setFixedSize(20, 20)
        search_icon.setAlignment(Qt.AlignCenter)
        
        self.search_edit = QLineEdit()
        self.search_edit.setPlaceholderText('搜索')
        self.search_edit.setStyleSheet("""
            QLineEdit {
                border: none;
                background-color: transparent;
                font-family: SimHei, Microsoft YaHei;
                font-size: 14px;
                color: #333;
            }
            QLineEdit::placeholder {
                color: #999;
            }
        """)
        self.search_edit.textChanged.connect(self.on_search_text_changed)
        
        search_container_layout.addWidget(search_icon)
        search_container_layout.addWidget(self.search_edit)
        
        search_layout.addWidget(search_container)
        
        # 創(chuàng)建功能按鈕區(qū)域
        features_widget = QWidget()
        features_widget.setStyleSheet("background-color: white; border-top: 1px solid #e0e0e0; border-bottom: 1px solid #e0e0e0;")
        features_layout = QHBoxLayout(features_widget)
        features_layout.setContentsMargins(15, 0, 15, 0)
        features_layout.setSpacing(0)
        
        # 創(chuàng)建功能按鈕
        self.chat_btn = QPushButton('聊天')
        self.contact_btn = QPushButton('聯(lián)系人')
        self.favorite_btn = QPushButton('收藏')
        
        # 設(shè)置按鈕樣式
        for btn in [self.chat_btn, self.contact_btn, self.favorite_btn]:
            btn.setFixedHeight(40)
            btn.setStyleSheet("""
                QPushButton {
                    border: none;
                    background-color: transparent;
                    font-family: SimHei, Microsoft YaHei;
                    font-size: 14px;
                    color: #666;
                    padding: 0 20px;
                }
                QPushButton:hover {
                    background-color: #f5f5f5;
                }
            """)
        
        # 設(shè)置默認(rèn)選中聊天按鈕 - 微信綠色主題
        self.chat_btn.setStyleSheet("""
            QPushButton {
                border: none;
                background-color: #e8f0fe;
                font-family: SimHei, Microsoft YaHei;
                font-size: 14px;
                color: #07c160;
                font-weight: bold;
                padding: 0 20px;
            }
            QPushButton:hover {
                background-color: #e8f0fe;
            }
        """)
        
        # 連接按鈕點(diǎn)擊信號(hào)
        self.chat_btn.clicked.connect(lambda: self.on_feature_button_clicked('chat'))
        self.contact_btn.clicked.connect(lambda: self.on_feature_button_clicked('contact'))
        self.favorite_btn.clicked.connect(lambda: self.on_feature_button_clicked('favorite'))
        
        features_layout.addWidget(self.chat_btn)
        features_layout.addWidget(self.contact_btn)
        features_layout.addWidget(self.favorite_btn)
        
        # 創(chuàng)建聊天列表
        self.chat_list = QListWidget()
        self.chat_list.setStyleSheet("""
            QListWidget {
                border: none;
                background-color: white;
            }
            QListWidget::item {
                height: 72px;
                border-bottom: 1px solid #f0f0f0;
            }
            QListWidget::item:hover {
                background-color: #f5f5f5;
            }
            QListWidget::item:selected {
                background-color: #e8f0fe;
            }
            QScrollBar:vertical {
                width: 6px;
                background-color: white;
            }
            QScrollBar::handle:vertical {
                background-color: #c0c0c0;
                border-radius: 3px;
            }
            QScrollBar::handle:vertical:hover {
                background-color: #a0a0a0;
            }
        """)
        
        # 連接聊天列表點(diǎn)擊信號(hào)
        self.chat_list.itemClicked.connect(self.on_chat_item_clicked)
        
        # 添加示例聊天項(xiàng)
        self.add_chat_item('仙女帥哥俱樂(lè)部', '盟詞: [陣營(yíng)] 公示! ...', '17:48', 'group.png')
        self.add_chat_item('Andy', '沒(méi)出現(xiàn)鍋巴吧', '17:01', 'user1.png')
        self.add_chat_item('0705-極簡(jiǎn)技術(shù)...', '康雨秋: 上課去了', '16:49', 'group.png')
        self.add_chat_item('折騰的群聊', '不坑老師做俯臥撐-12', '16:45', 'group.png')
        self.add_chat_item('學(xué)科網(wǎng) | 20...', '檸檬老師: 文案:', '16:44', 'group.png')
        self.add_chat_item('不坑老師付...', '康雨秋: [鏈接] 我把...', '16:39', 'group.png')
        self.add_chat_item('師門(mén) ?? ?? ??', '小號(hào): [圖片]', '16:22', 'group.png')
        self.add_chat_item('不坑老師私...', 'AI助理-波比 (道義干...', '16:16', 'user2.png')
        
        # 將所有部件添加到側(cè)邊欄布局
        sidebar_layout.addWidget(user_info_widget)
        sidebar_layout.addLayout(search_layout)
        sidebar_layout.addWidget(features_widget)
        sidebar_layout.addWidget(self.chat_list)
        
        # 將側(cè)邊欄添加到父部件
        parent.addWidget(sidebar)
    
    def add_chat_item(self, name, message, time, avatar_file):
        # 創(chuàng)建聊天項(xiàng)部件
        item_widget = QWidget()
        item_layout = QHBoxLayout(item_widget)
        item_layout.setContentsMargins(15, 10, 15, 10)
        
        # 頭像
        avatar_label = QLabel()
        # 創(chuàng)建圓形頭像
        avatar_pixmap = QPixmap(44, 44)
        avatar_pixmap.fill(Qt.transparent)
        painter = QPainter(avatar_pixmap)
        painter.setRenderHint(QPainter.Antialiasing)
        
        # 根據(jù)類(lèi)型設(shè)置不同的背景色
        if 'group' in avatar_file:
            painter.setBrush(QBrush(QColor(255, 193, 7)))  # 群聊使用橙色
        else:
            painter.setBrush(QBrush(QColor(100, 181, 246)))  # 個(gè)人聊天使用藍(lán)色
        
        painter.setPen(Qt.NoPen)
        painter.drawEllipse(0, 0, 44, 44)
        painter.end()
        
        avatar_label.setPixmap(avatar_pixmap)
        avatar_label.setFixedSize(44, 44)
        avatar_label.setScaledContents(True)
        
        # 右側(cè)信息區(qū)域
        info_widget = QWidget()
        info_layout = QVBoxLayout(info_widget)
        info_layout.setContentsMargins(0, 0, 0, 0)
        info_layout.setSpacing(4)
        
        # 名稱(chēng)和時(shí)間
        name_time_widget = QWidget()
        name_time_layout = QHBoxLayout(name_time_widget)
        name_time_layout.setContentsMargins(0, 0, 0, 0)
        name_time_layout.setSpacing(5)
        
        name_label = QLabel(name)
        name_label.setFont(QFont('SimHei', 14, QFont.Bold))
        name_label.setStyleSheet('color: #333;')
        name_label.setObjectName('chatNameLabel')  # 設(shè)置對(duì)象名以便查找
        
        time_label = QLabel(time)
        time_label.setFont(QFont('SimHei', 12))
        time_label.setStyleSheet('color: #999;')
        
        name_time_layout.addWidget(name_label)
        name_time_layout.addStretch()
        name_time_layout.addWidget(time_label)
        
        # 消息內(nèi)容
        message_label = QLabel(message)
        message_label.setFont(QFont('SimHei', 13))
        message_label.setStyleSheet('color: #666;')
        message_label.setMaximumWidth(200)
        message_label.setWordWrap(True)
        
        info_layout.addWidget(name_time_widget)
        info_layout.addWidget(message_label)
        
        # 添加到主布局
        item_layout.addWidget(avatar_label)
        item_layout.addWidget(info_widget, 1, Qt.AlignTop)
        
        # 創(chuàng)建列表項(xiàng)并設(shè)置部件
        item = QListWidgetItem()
        item.setSizeHint(item_widget.sizeHint())
        self.chat_list.addItem(item)
        self.chat_list.setItemWidget(item, item_widget)
        
        # 保存聊天信息
        item.setData(Qt.UserRole, {'name': name, 'message': message, 'time': time, 'avatar_file': avatar_file})
    
    def create_chat_area(self, parent):
        # 創(chuàng)建聊天區(qū)域框架
        chat_area = QWidget()
        chat_area.setStyleSheet("background-color: #f8f9fa;")
        chat_area_layout = QVBoxLayout(chat_area)
        chat_area_layout.setContentsMargins(0, 0, 0, 0)
        chat_area_layout.setSpacing(0)
        
        # 創(chuàng)建聊天頭部
        chat_header = QWidget()
        chat_header.setStyleSheet("background-color: white; border-bottom: 1px solid #e0e0e0;")
        chat_header_layout = QHBoxLayout(chat_header)
        chat_header_layout.setContentsMargins(15, 10, 10, 10)
        
        back_btn = QPushButton('←')
        back_btn.setFixedSize(36, 36)
        back_btn.setStyleSheet("""
            QPushButton {
                border: none;
                background-color: transparent;
                color: #333;
                font-size: 16px;
                border-radius: 18px;
            }
            QPushButton:hover {
                background-color: #f0f0f0;
            }
        """)
        back_btn.clicked.connect(self.on_back_button_clicked)
        
        # 聊天信息區(qū)域
        chat_info_widget = QWidget()
        chat_info_layout = QVBoxLayout(chat_info_widget)
        chat_info_layout.setContentsMargins(0, 0, 0, 0)
        chat_info_layout.setSpacing(2)
        
        # 聊天對(duì)象名稱(chēng)
        self.current_chat_name = QLabel('Andy')
        self.current_chat_name.setFont(QFont('SimHei', 14, QFont.Bold))
        self.current_chat_name.setStyleSheet("color: #333;")
        
        # 在線(xiàn)狀態(tài) - 微信風(fēng)格綠色圓點(diǎn)
        self.online_status = QLabel()
        self.online_status.setText('在線(xiàn)')
        self.online_status.setFont(QFont('SimHei', 11))
        self.online_status.setStyleSheet("color: #07c160;")
        
        chat_info_layout.addWidget(self.current_chat_name)
        chat_info_layout.addWidget(self.online_status)
        
        header_btns_widget = QWidget()
        header_btns_layout = QHBoxLayout(header_btns_widget)
        header_btns_layout.setSpacing(5)
        
        search_btn = QPushButton('??')
        voice_btn = QPushButton('??')
        video_btn = QPushButton('??')
        more_btn = QPushButton('?')
        more_btn.setFont(QFont('SimHei', 14))
        
        for btn in [search_btn, voice_btn, video_btn, more_btn]:
            btn.setFixedSize(36, 36)
            btn.setStyleSheet("""
                QPushButton {
                    border: none;
                    background-color: transparent;
                    color: #666;
                    font-size: 16px;
                }
                QPushButton:hover {
                    background-color: #f0f0f0;
                    border-radius: 18px;
                }
            """)
        
        header_btns_layout.addWidget(search_btn)
        header_btns_layout.addWidget(voice_btn)
        header_btns_layout.addWidget(video_btn)
        header_btns_layout.addWidget(more_btn)
        
        chat_header_layout.addWidget(back_btn)
        chat_header_layout.addWidget(chat_info_widget, 0, Qt.AlignVCenter)
        chat_header_layout.addStretch()
        chat_header_layout.addWidget(header_btns_widget)
        
        # 創(chuàng)建消息顯示區(qū)域
        self.message_area = QScrollArea()
        self.message_area.setWidgetResizable(True)
        self.message_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.message_area.setStyleSheet("""
            QScrollArea {
                background-color: #f8f9fa;
                border: none;
            }
            QScrollBar:vertical {
                width: 8px;
                background-color: transparent;
            }
            QScrollBar::handle:vertical {
                background-color: #c0c0c0;
                border-radius: 4px;
                margin: 4px 0;
            }
            QScrollBar::handle:vertical:hover {
                background-color: #a0a0a0;
            }
            QScrollBar::add-line:vertical,
            QScrollBar::sub-line:vertical {
                height: 0px;
            }
        """)
        
        self.message_widget = QWidget()
        self.message_widget.setStyleSheet("background-color: #f8f9fa;")
        self.message_layout = QVBoxLayout(self.message_widget)
        self.message_layout.setAlignment(Qt.AlignTop)
        self.message_layout.setSpacing(12)
        self.message_layout.setContentsMargins(15, 15, 15, 15)
        
        self.message_area.setWidget(self.message_widget)
        
        # 添加示例消息
        self.add_message('我一會(huì)回來(lái)再看看還能少點(diǎn)啥', False)
        self.add_message('可真行啊你', True)
        self.add_message('在干嘛!', False)
        self.add_message('不想理你', True)
        self.add_message('麗麗', False)
        self.add_message('什么意思', True)
        
        # 創(chuàng)建輸入?yún)^(qū)域
        input_area = QWidget()
        input_area.setStyleSheet("background-color: white; border-top: 1px solid #e0e0e0;")
        input_area_layout = QVBoxLayout(input_area)
        input_area_layout.setContentsMargins(15, 10, 15, 10)
        input_area_layout.setSpacing(8)
        
        # 工具按鈕區(qū)域
        tools_widget = QWidget()
        tools_layout = QHBoxLayout(tools_widget)
        tools_layout.setSpacing(8)
        
        # 工具按鈕樣式
        tool_btn_style = """
            QPushButton {
                border: none;
                background-color: transparent;
                font-size: 18px;
                border-radius: 18px;
            }
            QPushButton:hover {
                background-color: #f0f0f0;
                border-radius: 18px;
            }
        """
        
        emoji_btn = QPushButton('??')
        emoji_btn.setFixedSize(36, 36)
        emoji_btn.setStyleSheet(tool_btn_style)
        emoji_btn.clicked.connect(self.on_emoji_button_clicked)
        emoji_btn.setToolTip('表情')
        
        file_btn = QPushButton('??')
        file_btn.setFixedSize(36, 36)
        file_btn.setStyleSheet(tool_btn_style)
        file_btn.clicked.connect(self.on_file_button_clicked)
        file_btn.setToolTip('文件')
        
        image_btn = QPushButton('???')
        image_btn.setFixedSize(36, 36)
        image_btn.setStyleSheet(tool_btn_style)
        image_btn.clicked.connect(self.on_image_button_clicked)
        image_btn.setToolTip('圖片')
        
        voice_btn = QPushButton('??')
        voice_btn.setFixedSize(36, 36)
        voice_btn.setStyleSheet(tool_btn_style)
        voice_btn.clicked.connect(self.on_voice_button_clicked)
        voice_btn.setToolTip('語(yǔ)音')
        
        tools_layout.addWidget(emoji_btn)
        tools_layout.addWidget(file_btn)
        tools_layout.addWidget(image_btn)
        tools_layout.addWidget(voice_btn)
        tools_layout.addStretch()
        
        # 消息輸入框
        self.message_input = QTextEdit()
        self.message_input.setFixedHeight(80)
        self.message_input.setPlaceholderText('輸入消息...')
        self.message_input.setStyleSheet("""
            QTextEdit {
                border: 1px solid #ddd;
                border-radius: 6px;
                padding: 8px 10px;
                font-family: SimHei, Microsoft YaHei;
                font-size: 14px;
                background-color: white;
            }
            QTextEdit:focus {
                border-color: #07c160;
                outline: none;
            }
        """)
        # 監(jiān)聽(tīng)輸入框內(nèi)容變化,啟用/禁用發(fā)送按鈕
        self.message_input.textChanged.connect(self.on_message_text_changed)
        
        # 發(fā)送按鈕區(qū)域
        send_widget = QWidget()
        send_layout = QHBoxLayout(send_widget)
        
        self.send_btn = QPushButton('發(fā)送')
        self.send_btn.setFixedSize(86, 36)
        self.send_btn.setStyleSheet("""
            QPushButton {
                background-color: #07c160;
                color: white;
                border: none;
                border-radius: 18px;
                font-family: SimHei, Microsoft YaHei;
                font-size: 14px;
                font-weight: bold;
            }
            QPushButton:hover {
                background-color: #06b156;
            }
            QPushButton:disabled {
                background-color: #b3e8c5;
                color: #f0f0f0;
            }
        """)
        self.send_btn.clicked.connect(self.on_send_button_clicked)
        self.send_btn.setEnabled(False)  # 初始禁用
        
        send_layout.addStretch()
        send_layout.addWidget(self.send_btn)
        
        # 添加到輸入?yún)^(qū)域布局
        input_area_layout.addWidget(tools_widget)
        input_area_layout.addWidget(self.message_input)
        input_area_layout.addWidget(send_widget)
        
        # 將所有部件添加到聊天區(qū)域布局
        chat_area_layout.addWidget(chat_header)
        chat_area_layout.addWidget(self.message_area)
        chat_area_layout.addWidget(input_area)
        
        # 將聊天區(qū)域添加到父部件
        parent.addWidget(chat_area)
    
    def add_message(self, text, is_self=True, show_avatar=True):
        """添加消息到聊天區(qū)域 - 微信風(fēng)格"""
        # 創(chuàng)建消息容器
        message_container = QWidget()
        message_container_layout = QVBoxLayout(message_container)
        message_container_layout.setContentsMargins(0, 0, 0, 0)
        message_container_layout.setSpacing(2)
        
        # 創(chuàng)建消息項(xiàng)
        message_widget = QWidget()
        message_layout = QHBoxLayout(message_widget)
        message_layout.setContentsMargins(0, 0, 0, 0)
        message_layout.setSpacing(8)
        
        if is_self:
            # 自己發(fā)送的消息 - 微信綠色氣泡
            message_layout.setAlignment(Qt.AlignRight)
            
            # 發(fā)送時(shí)間
            time_label = QLabel(self.get_current_time())
            time_label.setFont(QFont('SimHei', 11))
            time_label.setStyleSheet("color: #999;")
            message_container_layout.addWidget(time_label, 0, Qt.AlignCenter)
            
            # 消息氣泡 - 微信綠色主題
            message_label = QLabel(text)
            message_label.setStyleSheet("""
                QLabel {
                    background-color: #07c160;
                    color: white;
                    border-radius: 10px;
                    border-bottom-right-radius: 4px;
                    padding: 8px 12px;
                    max-width: 60%;
                    white-space: pre-wrap;
                    font-family: SimHei, Microsoft YaHei;
                    font-size: 14px;
                    line-height: 1.4;
                }
            """)
            message_label.setWordWrap(True)
            message_label.setTextInteractionFlags(Qt.TextSelectableByMouse)
            
            message_layout.addWidget(message_label)
            
            # 檢查是否包含表情
            if any(emoji in text for emoji in ['??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??', '??']):
                status_label = QLabel('??')
                status_label.setStyleSheet("font-size: 16px;")
                message_layout.addWidget(status_label)
        else:
            # 對(duì)方發(fā)送的消息 - 微信白色氣泡
            message_layout.setAlignment(Qt.AlignLeft)
            
            # 發(fā)送時(shí)間
            time_label = QLabel(self.get_current_time())
            time_label.setFont(QFont('SimHei', 11))
            time_label.setStyleSheet("color: #999;")
            message_container_layout.addWidget(time_label, 0, Qt.AlignCenter)
            
            # 頭像
            if show_avatar:
                avatar_label = QLabel()
                avatar_pixmap = QPixmap(36, 36)
                # 創(chuàng)建圓形頭像 - 微信風(fēng)格
                painter = QPainter(avatar_pixmap)
                painter.setRenderHint(QPainter.Antialiasing)

                painter.setBrush(QBrush(QColor(100, 181, 246)))  # 個(gè)人聊天使用藍(lán)色
                painter.setPen(Qt.NoPen)
                painter.drawEllipse(0, 0, 36, 36)
                painter.end()
                
                avatar_label.setPixmap(avatar_pixmap)
                avatar_label.setFixedSize(36, 36)
                avatar_label.setScaledContents(True)
                message_layout.addWidget(avatar_label)
            else:
                # 如果不顯示頭像,添加一個(gè)占位符
                placeholder = QWidget()
                placeholder.setFixedWidth(36)
                message_layout.addWidget(placeholder)
            
            # 消息氣泡 - 微信白色主題
            message_label = QLabel(text)
            message_label.setStyleSheet("""
                QLabel {
                    background-color: white;
                    color: #333;
                    border-radius: 10px;
                    border-bottom-left-radius: 4px;
                    padding: 8px 12px;
                    max-width: 60%;
                    white-space: pre-wrap;
                    font-family: SimHei, Microsoft YaHei;
                    font-size: 14px;
                    line-height: 1.4;
                }
            """)
            message_label.setWordWrap(True)
            message_label.setTextInteractionFlags(Qt.TextSelectableByMouse)
            
            message_layout.addWidget(message_label)
        
        message_container_layout.addWidget(message_widget)
        
        # 添加到消息區(qū)域
        self.message_layout.addWidget(message_container)
        
        # 滾動(dòng)到底部
        self.message_area.verticalScrollBar().setValue(
            self.message_area.verticalScrollBar().maximum())
    
    def get_current_time(self):
        """獲取當(dāng)前時(shí)間,格式為HH:MM"""
        from datetime import datetime
        return datetime.now().strftime("%H:%M")
        
        # 添加到消息區(qū)域
        self.message_layout.addWidget(message_widget)
        
        # 滾動(dòng)到底部
        self.message_area.verticalScrollBar().setValue(
            self.message_area.verticalScrollBar().maximum())
    
    def on_chat_item_clicked(self, item):
        """處理聊天項(xiàng)點(diǎn)擊事件"""
        # 獲取聊天數(shù)據(jù)
        chat_data = item.data(Qt.UserRole)
        if chat_data:
            # 更新當(dāng)前聊天名稱(chēng)
            self.current_chat_name.setText(chat_data['name'])
            
            # 更新在線(xiàn)狀態(tài)(模擬)
            if 'group' in chat_data['avatar_file']:
                self.online_status.setText(f'群聊 · {chat_data["name"]}')
            else:
                # 隨機(jī)設(shè)置在線(xiàn)狀態(tài)
                import random
                statuses = ['在線(xiàn)', '最近在線(xiàn)', '正在輸入...', '已讀']
                self.online_status.setText(random.choice(statuses))
                
            # 清空現(xiàn)有消息
            for i in reversed(range(self.message_layout.count())):
                widget = self.message_layout.itemAt(i).widget()
                if widget:
                    widget.deleteLater()
            
            # 添加示例消息(模擬聊天記錄)
            if 'group' in chat_data['avatar_file']:
                self.add_message(f'歡迎來(lái)到{chat_data["name"]}', False)
                self.add_message('大家好!', True)
                self.add_message('這是一個(gè)群聊示例', False)
            else:
                self.add_message(f'你好,我是{chat_data["name"]}', False)
                self.add_message('你好!', True)
                self.add_message('今天過(guò)得怎么樣?', False)
        
        # 更新選中狀態(tài)的樣式
        for i in range(self.chat_list.count()):
            list_item = self.chat_list.item(i)
            widget = self.chat_list.itemWidget(list_item)
            if widget:
                # 重置所有項(xiàng)的樣式
                widget.setStyleSheet("")
        
        # 設(shè)置選中項(xiàng)的樣式
        selected_widget = self.chat_list.itemWidget(item)
        if selected_widget:
            selected_widget.setStyleSheet("background-color: #e8f0fe;")
            
            # 更新聊天列表中的消息(模擬)
            import random
            statuses = ['已讀', '未讀', '正在輸入...']
            for child in selected_widget.findChildren(QLabel):
                if child.objectName() == 'chatNameLabel':
                    # 更新名稱(chēng)(保持不變)
                    pass
                elif child.text() and not child.text().isdigit() and ':' not in child.text() and not any(c in child.text() for c in '0123456789'):
                    # 找到消息標(biāo)簽并更新
                    child.setText(random.choice(['收到', '好的', '明白了', '??', '??']))
    
    def on_search_text_changed(self):
        """處理搜索文本變化事件"""
        search_text = self.search_edit.text().lower()
        
        for i in range(self.chat_list.count()):
            item = self.chat_list.item(i)
            chat_data = item.data(Qt.UserRole)
            
            if chat_data:
                # 檢查名稱(chēng)或消息是否包含搜索文本
                match_name = search_text in chat_data['name'].lower()
                match_message = search_text in chat_data['message'].lower()
                
                # 顯示或隱藏項(xiàng)目
                item.setHidden(not (match_name or match_message))
    
    def on_feature_button_clicked(self, button_type):
        """處理功能按鈕點(diǎn)擊事件"""
        # 重置所有按鈕樣式
        for btn in [self.chat_btn, self.contact_btn, self.favorite_btn]:
            btn.setStyleSheet("""
                QPushButton {
                    border: none;
                    background-color: transparent;
                    font-family: SimHei, Microsoft YaHei;
                    font-size: 14px;
                    color: #666;
                    padding: 0 20px;
                }
                QPushButton:hover {
                    background-color: #f5f5f5;
                }
            """)
        
        # 設(shè)置選中按鈕的樣式
        if button_type == 'chat':
            self.chat_btn.setStyleSheet("""
                QPushButton {
                    border: none;
                    background-color: #e8f0fe;
                    font-family: SimHei, Microsoft YaHei;
                    font-size: 14px;
                    color: #07c160;
                    font-weight: bold;
                    padding: 0 20px;
                }
                QPushButton:hover {
                    background-color: #e8f0fe;
                }
            """)
            # 顯示聊天列表邏輯
            self.chat_list.show()
        elif button_type == 'contact':
            self.contact_btn.setStyleSheet("""
                QPushButton {
                    border: none;
                    background-color: #e8f0fe;
                    font-family: SimHei, Microsoft YaHei;
                    font-size: 14px;
                    color: #07c160;
                    font-weight: bold;
                    padding: 0 20px;
                }
                QPushButton:hover {
                    background-color: #e8f0fe;
                }
            """)
            # 這里可以實(shí)現(xiàn)顯示聯(lián)系人列表的邏輯
        elif button_type == 'favorite':
            self.favorite_btn.setStyleSheet("""
                QPushButton {
                    border: none;
                    background-color: #e8f0fe;
                    font-family: SimHei, Microsoft YaHei;
                    font-size: 14px;
                    color: #07c160;
                    font-weight: bold;
                    padding: 0 20px;
                }
                QPushButton:hover {
                    background-color: #e8f0fe;
                }
            """)
            # 這里可以實(shí)現(xiàn)顯示收藏列表的邏輯
    
    def on_back_button_clicked(self):
        """處理返回按鈕點(diǎn)擊事件"""
        # 這里可以實(shí)現(xiàn)返回上一級(jí)或切換視圖的功能
        pass
    
    def on_message_text_changed(self):
        """處理消息文本變化事件"""
        # 啟用或禁用發(fā)送按鈕
        text = self.message_input.toPlainText().strip()
        self.send_btn.setEnabled(bool(text))
        
        # 更新在線(xiàn)狀態(tài)為"正在輸入..."
        if "群聊" not in self.online_status.text() and bool(text):
            self.online_status.setText("對(duì)方正在輸入...")
            # 設(shè)置定時(shí)器,一段時(shí)間后恢復(fù)狀態(tài)
            self.input_timer = QTimer()
            self.input_timer.timeout.connect(self.reset_online_status)
            self.input_timer.setSingleShot(True)
            self.input_timer.start(2000)  # 2秒后恢復(fù)
    
    def reset_online_status(self):
        """重置在線(xiàn)狀態(tài)"""
        if not self.message_input.toPlainText().strip():
            import random
            statuses = ['在線(xiàn)', '最近在線(xiàn)', '已讀']
            self.online_status.setText(random.choice(statuses))
    
    def add_reply(self, reply_text):
        """添加回復(fù)消息"""
        self.add_message(reply_text, is_self=False)
    
    def update_chat_list_latest_message(self, latest_message):
        """更新聊天列表中的最新消息"""
        for i in range(self.chat_list.count()):
            list_item = self.chat_list.item(i)
            chat_data = list_item.data(Qt.UserRole)
            
            # 找到當(dāng)前選中的聊天項(xiàng)
            selected_widget = self.chat_list.itemWidget(list_item)
            if selected_widget and selected_widget.styleSheet() == "background-color: #e8f0fe;":
                # 更新時(shí)間
                current_time = self.get_current_time()
                for child in selected_widget.findChildren(QLabel):
                    if ':' in child.text() and any(c in child.text() for c in '0123456789'):
                        child.setText(current_time)
                
                # 更新消息預(yù)覽
                for child in selected_widget.findChildren(QLabel):
                    if child.objectName() != 'chatNameLabel' and ':' not in child.text() and not any(c in child.text() for c in '0123456789'):
                        # 截取消息預(yù)覽
                        preview = latest_message[:20] + '...' if len(latest_message) > 20 else latest_message
                        child.setText(preview)
    
    def on_send_button_clicked(self):
        """處理發(fā)送按鈕點(diǎn)擊事件"""
        text = self.message_input.toPlainText().strip()
        if text:
            # 添加消息到聊天區(qū)域
            self.add_message(text, is_self=True)
            
            # 更新聊天列表中的最新消息
            self.update_chat_list_latest_message(text)
            
            # 清空輸入框
            self.message_input.clear()
            
            # 禁用發(fā)送按鈕
            self.send_btn.setEnabled(False)
            
            # 重置在線(xiàn)狀態(tài)
            import random
            statuses = ['在線(xiàn)', '最近在線(xiàn)', '已讀']
            self.online_status.setText(random.choice(statuses))
            
            # 模擬回復(fù)(隨機(jī)延遲后自動(dòng)回復(fù))
            self.simulate_reply(text)
            
            # 這里可以添加發(fā)送消息到服務(wù)器的邏輯
    
    def simulate_reply(self, message_text):
        """模擬自動(dòng)回復(fù)功能"""
        # 定義一些簡(jiǎn)單的回復(fù)模式
        replies = {
            '你好': '你好!很高興見(jiàn)到你!',
            '在嗎': '我在呢,有什么可以幫你的?',
            '早上好': '早上好!祝你有美好的一天!',
            '晚上好': '晚上好!今天過(guò)得怎么樣?',
            '謝謝': '不客氣!',
            '再見(jiàn)': '再見(jiàn)!下次再聊!'
        }
        
        # 檢查是否有匹配的回復(fù)
        reply_text = None
        for keyword, reply in replies.items():
            if keyword in message_text:
                reply_text = reply
                break
        
        # 如果沒(méi)有匹配的回復(fù),生成隨機(jī)回復(fù)
        if not reply_text:
            import random
            random_replies = [
                '好的,我知道了。',
                '明白,我會(huì)處理的。',
                '這個(gè)問(wèn)題很有趣,能詳細(xì)說(shuō)說(shuō)嗎?',
                '我理解你的意思。',
                '讓我想想...',
                '收到!'
            ]
            reply_text = random.choice(random_replies)
        
        # 設(shè)置定時(shí)器,模擬延遲回復(fù)
        self.reply_timer = QTimer()
        self.reply_timer.timeout.connect(lambda: self.add_reply(reply_text))
        self.reply_timer.setSingleShot(True)
        
        import random
        delay = random.randint(1000, 3000)  # 1-3秒的隨機(jī)延遲
        self.reply_timer.start(delay)
    
    def on_file_button_clicked(self):
        """處理文件按鈕點(diǎn)擊事件"""
        options = QFileDialog.Options()
        file_path, _ = QFileDialog.getOpenFileName(
            self, "選擇文件", "", "所有文件 (*);;文檔 (*.doc *.docx *.pdf *.txt);;圖片 (*.png *.jpg *.jpeg)", options=options)
        if file_path:
            # 顯示文件路徑作為消息
            file_name = os.path.basename(file_path)
            self.add_message(f'?? {file_name}', is_self=True)
    
    def on_emoji_button_clicked(self):
        """處理表情按鈕點(diǎn)擊事件"""
        # 顯示表情面板
        self.show_emoji_panel()
        
    def on_image_button_clicked(self):
        """圖片按鈕點(diǎn)擊事件"""
        # 簡(jiǎn)單實(shí)現(xiàn),實(shí)際項(xiàng)目中可能需要打開(kāi)文件選擇器
        pass

    def on_voice_button_clicked(self):
        """語(yǔ)音按鈕點(diǎn)擊事件"""
        # 簡(jiǎn)單實(shí)現(xiàn),實(shí)際項(xiàng)目中可能需要錄音功能
        pass

    def on_video_button_clicked(self):
        """視頻按鈕點(diǎn)擊事件"""
        # 簡(jiǎn)單實(shí)現(xiàn),實(shí)際項(xiàng)目中可能需要視頻錄制功能
        pass

    def on_search_button_clicked(self):
        """處理搜索按鈕點(diǎn)擊事件"""
        QMessageBox.information(self, "搜索", "聊天記錄搜索功能暫未實(shí)現(xiàn)")

    def search_emojis(self, search_text):
        """搜索表情功能"""
        # 這里只是簡(jiǎn)單的實(shí)現(xiàn),實(shí)際應(yīng)用中可以根據(jù)表情名稱(chēng)或描述進(jìn)行搜索
        # 由于我們只有表情符號(hào),這里只是為了演示搜索框的功能
        search_text = search_text.strip().lower()
        if not search_text:
            # 如果搜索框?yàn)榭?,恢?fù)所有表情
            self.reset_emoji_view()
            return
        
        # 這里可以實(shí)現(xiàn)更復(fù)雜的搜索邏輯
        # 簡(jiǎn)單的實(shí)現(xiàn):顯示常用表情或提示"未找到"
        if hasattr(self.emoji_search_box, 'last_search') and self.emoji_search_box.last_search == search_text:
            return
        
        self.emoji_search_box.last_search = search_text
        
        # 這里可以添加實(shí)際的搜索邏輯
        
    def reset_emoji_view(self):
        """重置表情視圖"""
        # 重置搜索框
        if hasattr(self.emoji_search_box, 'last_search'):
            delattr(self.emoji_search_box, 'last_search')

    def eventFilter(self, obj, event):
        """事件過(guò)濾器,用于處理表情面板的點(diǎn)擊事件"""
        # 處理全局點(diǎn)擊事件以關(guān)閉表情面板
        if event.type() == QEvent.MouseButtonPress:
            # 如果點(diǎn)擊的不是表情面板或表情按鈕,關(guān)閉表情面板
            if hasattr(self, 'emoji_panel') and self.emoji_panel.isVisible():
                # 檢查是否點(diǎn)擊了表情面板
                if not self.emoji_panel.rect().contains(self.emoji_panel.mapFromGlobal(event.globalPos())):
                    # 檢查是否點(diǎn)擊了表情按鈕
                    if hasattr(self, 'emoji_btn'):
                        btn_rect = self.emoji_btn.rect()
                        btn_global_pos = self.emoji_btn.mapToGlobal(QPoint(0, 0))
                        btn_global_rect = QRect(btn_global_pos, btn_rect.size())
                        if not btn_global_rect.contains(event.globalPos()):
                            self.emoji_panel.close()
        return super().eventFilter(obj, event)

    def show_emoji_panel(self):
        """顯示表情面板"""
        # 如果表情面板不存在,創(chuàng)建它
        if not hasattr(self, 'emoji_panel'):
            self.emoji_panel = QWidget(self)
            self.emoji_panel.setWindowFlags(Qt.Popup | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
            self.emoji_panel.setStyleSheet("""
                QWidget {
                    background-color: white;
                    border: 1px solid #ddd;
                    border-radius: 6px;
                }
            """)
            
            # 創(chuàng)建表情面板布局
            emoji_layout = QGridLayout(self.emoji_panel)
            emoji_layout.setSpacing(8)
            emoji_layout.setContentsMargins(12, 12, 12, 12)
            
            # 常用表情列表
            emojis = [
                '??', '??', '??', '??', '??', '??', '??', '??',
                '??', '??', '??', '??', '??', '??', '??', '??',
                '??', '??', '??', '??', '??', '??', '??', '??',
                '??', '??', '??', '??', '??', '??', '??', '??',
                '??', '??', '??', '??', '??', '??', '??', '??',
                '??', '??', '??', '??', '??', '??', '??', '??',
                '??', '??', '??', '??', '??', '??', '??', '??',
                '??', '??', '??', '??', '??', '??', '??', '??'
            ]
            
            # 添加表情按鈕
            row, col = 0, 0
            for emoji in emojis:
                btn = QPushButton(emoji)
                btn.setFixedSize(36, 36)
                btn.setStyleSheet("""
                    QPushButton {
                        border: none;
                        background-color: transparent;
                        font-size: 20px;
                    }
                    QPushButton:hover {
                        background-color: #f0f0f0;
                        border-radius: 4px;
                    }
                """)
                btn.clicked.connect(lambda checked, e=emoji: self.add_emoji_to_input(e))
                emoji_layout.addWidget(btn, row, col)
                
                col += 1
                if col >= 8:
                    col = 0
                    row += 1
            
            # 調(diào)整面板大小
            self.emoji_panel.adjustSize()
            
            # 確保事件過(guò)濾器被正確安裝
            QApplication.instance().installEventFilter(self)
        
        # 計(jì)算面板位置(在輸入框上方)
        input_pos = self.message_input.mapToGlobal(QPoint(0, 0))
        panel_x = input_pos.x()
        panel_y = input_pos.y() - self.emoji_panel.height() - 10
        
        # 確保面板不會(huì)超出屏幕邊界
        screen_geometry = QApplication.desktop().availableGeometry()
        if panel_y < screen_geometry.top():
            panel_y = input_pos.y() + self.message_input.height() + 10
        if panel_x + self.emoji_panel.width() > screen_geometry.right():
            panel_x = screen_geometry.right() - self.emoji_panel.width() - 10
        
        # 顯示面板
        self.emoji_panel.move(panel_x, panel_y)
        self.emoji_panel.raise_()
        self.emoji_panel.setFocus()
        self.emoji_panel.show()

    def add_emoji_to_input(self, emoji):
        """添加表情到輸入框"""
        # 獲取當(dāng)前光標(biāo)位置
        cursor = self.message_input.textCursor()
        cursor.insertText(emoji)
        self.message_input.setTextCursor(cursor)
        self.message_input.setFocus()
        
        # 更新發(fā)送按鈕狀態(tài)
        self.send_btn.setEnabled(bool(self.message_input.toPlainText().strip()))
        
        # 關(guān)閉表情面板
        if hasattr(self, 'emoji_panel') and self.emoji_panel.isVisible():
            self.emoji_panel.close()

# 主函數(shù)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    # 設(shè)置應(yīng)用程序樣式
    app.setStyle('Fusion')
    
    # 設(shè)置全局樣式
    app.setStyleSheet("""
        QApplication {
            font-family: SimHei, Microsoft YaHei, Arial, sans-serif;
        }
    """)
    
    # 創(chuàng)建并顯示主窗口
    window = WeChatClone()
    window.show()
    
    # 運(yùn)行應(yīng)用程序
    sys.exit(app.exec_())

以上就是Python結(jié)合PyQt5模擬實(shí)現(xiàn)微信程序聊天功能的詳細(xì)內(nèi)容,更多關(guān)于Python微信聊天的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python實(shí)現(xiàn)網(wǎng)絡(luò)聊天室的示例代碼(支持多人聊天與私聊)

    Python實(shí)現(xiàn)網(wǎng)絡(luò)聊天室的示例代碼(支持多人聊天與私聊)

    這篇文章主要介紹了Python實(shí)現(xiàn)網(wǎng)絡(luò)聊天室的示例代碼(支持多人聊天與私聊),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 10款最好的Python開(kāi)發(fā)編輯器

    10款最好的Python開(kāi)發(fā)編輯器

    這篇文章主要介紹了10款最好的Python開(kāi)發(fā)編輯器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • python讀取多層嵌套文件夾中的文件實(shí)例

    python讀取多層嵌套文件夾中的文件實(shí)例

    今天小編就為大家分享一篇python讀取多層嵌套文件夾中的文件實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • Python獲取時(shí)光網(wǎng)電影數(shù)據(jù)的實(shí)例代碼

    Python獲取時(shí)光網(wǎng)電影數(shù)據(jù)的實(shí)例代碼

    這篇文章主要介紹了Python獲取時(shí)光網(wǎng)電影數(shù)據(jù),基本原理是先通過(guò)requests庫(kù),通過(guò)時(shí)光網(wǎng)自帶的電影數(shù)據(jù)API接口,獲取到指定的電影數(shù)據(jù),本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • 詳解Python中的argparse模塊

    詳解Python中的argparse模塊

    這篇文章主要介紹了詳解Python中的argparse模塊,argparse可以讓你輕松地編寫(xiě)用戶(hù)友好的命令行界面,定義你的程序需要的參數(shù),自動(dòng)生成幫助和用法信息,需要的朋友可以參考下
    2023-07-07
  • Python簡(jiǎn)單實(shí)現(xiàn)詞云圖代碼及步驟解析

    Python簡(jiǎn)單實(shí)現(xiàn)詞云圖代碼及步驟解析

    這篇文章主要介紹了Python簡(jiǎn)單實(shí)現(xiàn)詞云圖代碼解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • python數(shù)字圖像處理實(shí)現(xiàn)直方圖與均衡化

    python數(shù)字圖像處理實(shí)現(xiàn)直方圖與均衡化

    在圖像處理中,直方圖是非常重要,也是非常有用的一個(gè)處理要素。這篇文章主要介紹了python數(shù)字圖像處理實(shí)現(xiàn)直方圖與均衡化,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Python使用scipy保存圖片的一些注意點(diǎn)

    Python使用scipy保存圖片的一些注意點(diǎn)

    這篇文章主要介紹了Python使用scipy保存圖片的一些注意點(diǎn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • Python學(xué)習(xí)筆記_數(shù)據(jù)排序方法

    Python學(xué)習(xí)筆記_數(shù)據(jù)排序方法

    Python對(duì)數(shù)據(jù)排序有兩種方法:下面我們來(lái)簡(jiǎn)單分析下
    2014-05-05
  • Python pyautogui模擬鍵盤(pán)輸入操作的示例詳解

    Python pyautogui模擬鍵盤(pán)輸入操作的示例詳解

    在自動(dòng)化辦公和提高工作效率的今天,Python的pyautogui庫(kù)成為了我們模擬鍵盤(pán)和鼠標(biāo)操作的得力助手,下面我們看看如何使用pyautogui來(lái)模擬鍵盤(pán)輸入吧
    2025-03-03

最新評(píng)論

溧水县| 临沂市| 临颍县| 申扎县| 宕昌县| 攀枝花市| 盈江县| 茌平县| 迁西县| 淳化县| 乃东县| 虹口区| 玉门市| 津市市| 滦南县| 怀宁县| 河池市| 玉屏| 五指山市| 乌鲁木齐县| 微山县| 勐海县| 赫章县| 大安市| 龙口市| 邵阳市| 柳州市| 安图县| 东阳市| 镇江市| 五大连池市| 巩义市| 确山县| 浪卡子县| 苏州市| 湛江市| 枝江市| 松滋市| 河源市| 肥城市| 遂昌县|