#!/usr/bin/env python
# coding=utf-8
import tkinter as tk
import tkinter.messagebox as tkMessageBox
import requests

def send_message():
    content = txt_input.get('0.0', tk.END)
    payload = {'text': content}
    r = requests.get('http://localhost:8000/chatgpt', params=payload)
    response = r.json()
    txt_response.delete('0.0', tk.END)
    txt_response.insert('0.0', response['response'])

window = tk.Tk()
window.title('ChatGPT')
window.geometry('400x500')

lbl_input = tk.Label(window, text='Input:')
lbl_input.pack()

txt_input = tk.Text(window)
txt_input.pack()

btn_send = tk.Button(window, text='Send', command=send_message)
btn_send.pack()

lbl_response = tk.Label(window, text='Response:')
lbl_response.pack()

txt_response = tk.Text(window)
txt_response.pack()

window.mainloop()
Python ChatGPT GUI: 使用Tkinter创建图形化聊天脚本

原文地址: https://www.cveoy.top/t/topic/lmtf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录