[Python] 纯文本查看 复制代码
import tkinter as tk
from tkinter import ttk
import getpass,requests,os
class PyWinDesign:
def __init__(self, 启动窗口):
self.启动窗口 = 启动窗口
self.启动窗口.title('学小易查题接口PC ——by 浅山藏')
self.启动窗口.resizable(width=True, height=True)
screenwidth = self.启动窗口.winfo_screenwidth()
screenheight = self.启动窗口.winfo_screenheight()
size = '%dx%d+%d+%d' % (596, 430, (screenwidth - 596) / 2, (screenheight - 430) / 2)
self.启动窗口.geometry(size)
self.标签1_标题 = tk.StringVar()
self.标签1_标题.set('账号:')
self.标签1 = tk.Label(self.启动窗口,textvariable=self.标签1_标题,anchor=tk.W)
self.标签1.place(x=380,y=19,width=35,height=25)
self.标签2_标题 = tk.StringVar()
self.标签2_标题.set('密码:')
self.标签2 = tk.Label(self.启动窗口,textvariable=self.标签2_标题,anchor=tk.W)
self.标签2.place(x=381,y=50,width=36,height=27)
self.编辑框1 = tk.Text(self.启动窗口,wrap=tk.NONE)
self.编辑框1.insert(tk.END,'')
self.编辑框1.place(x=438,y=19,width=150,height=25)
self.编辑框2_标题 = tk.StringVar()
self.编辑框2 =tk.Entry(self.启动窗口, textvariable=self.编辑框2_标题, show='*')
self.编辑框2.place(x=438,y=54,width=150,height=25)
self.按钮1_标题 = tk.StringVar()
self.按钮1_标题.set('登录')
self.按钮1 = tk.Button(self.启动窗口,textvariable=self.按钮1_标题,command=self.按钮1_被鼠标左键单击)
self.按钮1.place(x=483,y=90,width=56,height=41)
self.编辑框3 = tk.Text(self.启动窗口,wrap=tk.NONE)
self.编辑框3.insert(tk.END,'')
self.编辑框3.place(x=22,y=26,width=332,height=55)
self.按钮2_标题 = tk.StringVar()
self.按钮2_标题.set('查题')
self.按钮2 = tk.Button(self.启动窗口,textvariable=self.按钮2_标题,command=self.按钮2_被鼠标左键单击)
self.按钮2.place(x=141,y=92,width=71,height=40)
self.编辑框4_滚动条_纵 = tk.Scrollbar(self.启动窗口)
self.编辑框4_滚动条_纵.place(x=568,y=147,width=18,height=275)
self.编辑框4 = tk.Text(self.启动窗口,yscrollcommand=self.编辑框4_滚动条_纵.set,wrap=tk.WORD)
self.编辑框4_滚动条_纵.config(command=self.编辑框4.yview)
self.编辑框4.insert(tk.END,'')
self.编辑框4.place(x=13,y=147,width=555,height=275)
if os.path.exists('.\\token.txt'):
self.编辑框4.insert(tk.END,'检测到token,无需登录,若查题失败请尝试重新登录\n本软件只调用接口,如若封号,概不负责\n——by 浅山藏')
f = open('token.txt')
global token
token = f.read()
else:
self.编辑框4.insert(tk.END,'请先用学小易账号密码进行登录\n本软件只调用接口,如若封号,概不负责\n——by 浅山藏')
def 按钮1_被鼠标左键单击(self):
self.编辑框4.delete('1.0','end')
user = self.编辑框1.get('0.0','end')
password = self.编辑框2.get()
url = 'https://app.51xuexiaoyi.com/api/v1/login'
data = {
'username':user,
'password':password
}
headers ={
'platform': 'android',
'app-version': '1.0.6',
'User-Agent': 'okhttp/3.11.0'
}
req = requests.post(url,headers=headers,data=data).json()
code = req['code']
if code ==200:
self.编辑框4.delete('1.0','end')
self.编辑框4.insert(tk.END,'登录成功\n——by 浅山藏')
global token
token = req['data']['api_token']
f = open('token.txt','w')
f.write(token)
f.close()
else:
self.编辑框4.insert(tk.END,'登录失败,请检查账号密码重试\n——by 浅山藏')
def 按钮2_被鼠标左键单击(self):
self.编辑框4.delete('1.0','end')
keyword = self.编辑框3.get('0.0','end')
url ='https://app.51xuexiaoyi.com/api/v1/searchQuestion'
global token
headers = {
'token': token,
'platform': 'android',
'app-version': '1.0.6',
'User-Agent': 'okhttp/3.11.0'
}
data = {
"keyword":keyword
}
req = requests.post(url,headers=headers,data=data).json()
answers = ''
for i in range (0,len(req['data'])):
question = req['data'][i]['q']
answer = req['data'][i]['a']
answers = answers + '题目:'+question + '\n' +'答案:'+ answer +'\n\n'
self.编辑框4.insert(tk.END,answers)
if __name__ == '__main__':
root = tk.Tk()
root.attributes("-alpha",1)
root.attributes("-topmost", True)
app = PyWinDesign(root)
root.mainloop()