#!/usr/bin/env python3
from PyQt5.QtWidgets import \
QWidget, QMainWindow, QAction, QVBoxLayout, QLineEdit, QPushButton, QTextEdit, QMessageBox, QApplication
from PyQt5.QtGui import QTextCursor, QIcon
from PyQt5.QtNetwork import QTcpSocket
from PyQt5.QtCore import Qt
class MyWidget(QWidget):
server_chinese_encoding = 'gbk'
def __init__(self):
QWidget.__init__(self)
self.sock = None
self.isConnectedToServer = False
self.textEdit = None
self.lineEdit = None
self.pushButton = None
self.vBox = None
self._create_widgets()
def _create_widgets(self):
self.textEdit = QTextEdit()
self.textEdit.setReadOnly(True)
p = self.textEdit.viewport().palette()
p.setColor(self.textEdit.viewport().backgroundRole(), Qt.transparent)
self.textEdit.viewport().setPalette(p)
self.lineEdit = QLineEdit()
self.lineEdit.setPlaceholderText("Enter message")
self.lineEdit.setMaxLength(50)
self.lineEdit.setEnabled(False)
self.pushButton = QPushButton("Send")
self.pushButton.setEnabled(False)
self.vBox = QVBoxLayout(self)
self.vBo
PyQt5 QTcpSocket 样例代码
最新推荐文章于 2024-07-23 00:06:26 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)