我要求的是写出ui界面
时间: 2024-06-09 13:04:43 浏览: 7
好的,以下是一个简单的 UI 界面样例,你可以根据自己的需求进行修改:
```python
import tkinter as tk
class ChatUI:
def __init__(self):
self.root = tk.Tk()
self.root.title("ChitGPT Chat")
self.root.geometry("500x500")
self.create_widgets()
def create_widgets(self):
# 聊天记录框
self.record_box = tk.Text(self.root, width=60, height=20)
self.record_box.pack(pady=10)
# 输入框
self.input_box = tk.Entry(self.root, width=50)
self.input_box.pack(side=tk.LEFT, padx=10, pady=10)
# 发送按钮
self.send_button = tk.Button(self.root, text="Send", command=self.send_message)
self.send_button.pack(side=tk.LEFT, padx=10, pady=10)
# 清空按钮
self.clear_button = tk.Button(self.root, text="Clear", command=self.clear_record)
self.clear_button.pack(side=tk.LEFT, padx=10, pady=10)
# 退出按钮
self.quit_button = tk.Button(self.root, text="Quit", command=self.root.quit)
self.quit_button.pack(side=tk.LEFT, padx=10, pady=10)
def send_message(self):
message = self.input_box.get()
# 在聊天记录框中添加新的对话
self.record_box.insert(tk.END, "You: " + message + "\n")
# 调用 ChatGPT 进行回答
answer = self.ChatGPT.get_response(message)
# 在聊天记录框中添加 AI 的回答
self.record_box.insert(tk.END, "AI: " + answer + "\n")
# 清空输入框
self.input_box.delete(0, tk.END)
def clear_record(self):
# 清空聊天记录框
self.record_box.delete(1.0, tk.END)
```
使用方法:
```python
# 实例化 ChatUI 类并运行
chat_ui = ChatUI()
chat_ui.root.mainloop()
```
注意,以上代码中的 `self.ChatGPT` 需要根据你的实际情况进行修改,确保能够调用到你自己开发的 ChitGPT 模型。此外,这只是一个简单的 UI 界面,你可以根据自己的需求进行修改和美化。