以下是实现该功能的 Python 代码:

import tkinter as tk
import requests

def sendtoserver(_webvpn_key, JSESSIONID1, JSESSIONID2):
    # 发送请求到服务器并返回响应结果
    url = 'http://example.com/api'
    headers = {
        'Cookie': f'_webvpn_key={_webvpn_key}; JSESSIONID={JSESSIONID1}; JSESSIONID2={JSESSIONID2}'
    }
    response = requests.get(url, headers=headers)
    return response.text

def on_submit():
    # 获取文本框的值并调用 sendtoserver 函数
    _webvpn_key = entry1.get()
    JSESSIONID1 = entry2.get()
    JSESSIONID2 = entry3.get()
    result = sendtoserver(_webvpn_key, JSESSIONID1, JSESSIONID2)

    # 在列表框中添加返回结果
    listbox.insert(tk.END, result)

# 创建主窗口和文本框
window = tk.Tk()
window.title('发送数据到服务器')
label1 = tk.Label(window, text='_webvpn_key:')
label1.grid(row=0, column=0)
entry1 = tk.Entry(window)
entry1.grid(row=0, column=1)
label2 = tk.Label(window, text='JSESSIONID1:')
label2.grid(row=1, column=0)
entry2 = tk.Entry(window)
entry2.grid(row=1, column=1)
label3 = tk.Label(window, text='JSESSIONID2:')
label3.grid(row=2, column=0)
entry3 = tk.Entry(window)
entry3.grid(row=2, column=1)

# 创建确定按钮
submit_button = tk.Button(window, text='确定', command=on_submit)
submit_button.grid(row=3, column=0, columnspan=2)

# 创建列表框
listbox = tk.Listbox(window)
listbox.grid(row=4, column=0, columnspan=2)

# 进入主循环
window.mainloop()

在该代码中,我们首先定义了一个 sendtoserver 函数,用于发送请求到服务器并返回响应结果。然后创建了一个主窗口和三个文本框,以及一个确定按钮和一个列表框。在点击确定按钮时,我们获取三个文本框的值,并调用 sendtoserver 函数,将返回的结果添加到列表框中展示给用户。最后,我们进入主循环,等待用户操作。


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

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