pyqt 类似QQ的程序代码
时间: 2023-03-28 22:02:49 浏览: 68
我可以回答这个问题。您可以使用PyQt来编写类似QQ的程序。以下是一个简单的示例代码:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QTextEdit
class ChatWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('QQ')
self.setGeometry(100, 100, 800, 600)
# 创建控件
self.chat_history = QTextEdit()
self.chat_input = QLineEdit()
self.send_button = QPushButton('发送')
# 布局
vbox = QVBoxLayout()
vbox.addWidget(self.chat_history)
hbox = QHBoxLayout()
hbox.addWidget(self.chat_input)
hbox.addWidget(self.send_button)
vbox.addLayout(hbox)
self.setLayout(vbox)
# 绑定事件
self.send_button.clicked.connect(self.send_message)
def send_message(self):
message = self.chat_input.text()
self.chat_history.append(message)
self.chat_input.clear()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = ChatWindow()
window.show()
sys.exit(app.exec_())
```
这是一个简单的聊天窗口,包括一个文本框用于显示聊天记录,一个文本框用于输入消息,以及一个发送按钮。当用户点击发送按钮时,程序会将输入的消息添加到聊天记录中,并清空输入框。