|
| 1 | +# coding=utf-8 |
| 2 | +## |
| 3 | +# Author : Luoofan |
| 4 | +# Date : 2020-03-11 09:15:44 |
| 5 | +# LastEditors: Luoofan |
| 6 | +# LastEditTime: 2020-03-13 16:26:14 |
| 7 | +# Description :SearchAns |
| 8 | +# FilePath : \SearchAns.py |
| 9 | +# |
| 10 | + |
| 11 | +import tkinter as tk |
| 12 | +from tkinter import ttk |
| 13 | +from ast import literal_eval |
| 14 | +from re import sub |
| 15 | +from urllib.parse import quote |
| 16 | +from requests import post |
| 17 | +from requests import get |
| 18 | + |
| 19 | +win = tk.Tk() |
| 20 | +win.title("SearchAns") |
| 21 | +win.geometry('505x230') # 设定窗口大小 |
| 22 | + |
| 23 | +# win.resizable(0, 0) # Disable resizing the GUI |
| 24 | +tabControl = ttk.Notebook(win) # Create Tab Control |
| 25 | + |
| 26 | +tab1 = ttk.Frame(tabControl) # Create a tab |
| 27 | +tabControl.add(tab1, text="Normal") # Add the tab |
| 28 | + |
| 29 | +#tab2 = ttk.Frame(tabControl) # Add a second tab |
| 30 | +#tabControl.add(tab2, text="Exact") # Make second tab visible |
| 31 | + |
| 32 | +tabControl.pack(expand=1, fill="both") # Pack to make visible |
| 33 | + |
| 34 | +# Tab1控件介绍 |
| 35 | +monty = ttk.LabelFrame(tab1, text="Main") |
| 36 | +monty.grid(column=0, row=0, padx=10, pady=4, ipady=5) |
| 37 | +# tab1 input |
| 38 | +ttk.Label(monty, text="题目:", font=('Arial', 12), width=5).grid(column=0, row=0, padx=5) # , sticky='E') |
| 39 | +queText = tk.Text(monty, font=('Arial', 12), width=40, height=3) |
| 40 | +queText.grid(column=1, row=0, rowspan=2) # ,sticky='W') |
| 41 | +# tab1 button |
| 42 | + |
| 43 | + |
| 44 | +def query_ans_normal(ev=None): |
| 45 | + global res |
| 46 | + q = quote(queText.get('0.0', 'end')) |
| 47 | + url = 'http://api.xmlm8.com/tk.php?t='+q |
| 48 | + ret_da = literal_eval(get(url).text) |
| 49 | + res.set("que:"+ret_da['tm']+'\n'+"ans:"+ret_da['da']) |
| 50 | + queText.delete('1.0', 'end') |
| 51 | + |
| 52 | + |
| 53 | +queText.bind("<Return>", query_ans_normal) |
| 54 | +go = ttk.Button(monty, text='Go', width=5, command=query_ans_normal) |
| 55 | +go.grid(column=2, row=0, rowspan=2, sticky="n" + "s", padx=5) |
| 56 | +# tab1 output |
| 57 | +ttk.Label(monty, text="结果:", font=('Arial', 12), width=5).grid(column=0, row=3, padx=5, pady=5) |
| 58 | +res = tk.StringVar() |
| 59 | +tk.Label(monty, height=5, textvariable=res, font=('Arial', 12), width=45, wraplength=400, justify='left', anchor='w').grid( |
| 60 | + column=1, row=3, rowspan=3, columnspan=2, pady=5, sticky="n"+"s") |
| 61 | +#for child in monty.winfo_children(): |
| 62 | +# child.grid_configure(padx=5, pady=1) |
| 63 | + |
| 64 | + |
| 65 | +#win.iconbitmap('./searchans.ico') |
| 66 | +win.mainloop() |
0 commit comments