Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3648527
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2021-08-24 17:19:24

# -*- codeing = utf-8 -*-

# @Time : 2021/8/20 16:22

# @File : translate.py

# @Software : PyCharm

import requests

import re

import tkinter as tk

from tkinter import ttk

from tkinter import *

Findresult = re.compile(r'class="transtext">(.*?)
')

head = {

    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67",

    "Cookie":"dreye[sys_lang]=gb; phpbb3_jb4z2_u=1; phpbb3_jb4z2_k=; phpbb3_jb4z2_sid=05e7f02ea96bb4513874e06033c06885; PHPSESSID=hgsargck54cmtepq06cb39ahm0"

}

def TransLate():

    url = ""

    d_after.insert('0.0',"")

    data = {

        "t_value":test.get(),

        "from": "zh-CHS",

        "to": "en",

        "sbt": "翻译",

        "t_r": ""

    }

    if d_com.get() == "英译中":

        data['from'] = "en"

        data['to'] = "zh-CHS"

    print(data['to'])

    res = ""

    while len(res) == 0:

        response = requests.post(url, data=data, headers=head)

        text = response.content.decode("utf-8")

        text = str(text)

        res = re.findall(Findresult,text)[1]

    d_after.insert('0.0',res)

root = tk.Tk()

root.minsize(430,200)

root.maxsize(430,200)

root.title('千度翻译')

root.attributes("-alpha",0.8)

l_befor = tk.Label(root,text='翻译前',font=10,width=10)

l_befor.grid(row=0,column=0)

d_com = ttk.Combobox(root,font=23,width=7)

d_com['value'] = ("中译英","英译中","待定..")

d_com.grid(row=0,column=1)

d_com.current(0)

test = tk.Entry(root,font=100,width=50)

test.grid(row=1,columnspan=2)

l_after = tk.Label(root,text='翻译后',font=20,width=10)

l_after.grid(row=2,column=0)

d_after = tk.Text(root,width=50,height=3,font=100)

d_after.grid(row=3,columnspan=2)

d_button = tk.Button(root,text='翻译',font=25,height=2,width=11,command=TransLate)

d_button.grid(row=4,column=0)

def Call_C_B():

    if v.get()==1:

        root.wm_attributes('-topmost', 1)

    else:

        root.wm_attributes('-topmost', 0)

        v.set(0)

v = IntVar()

d_selet = tk.Checkbutton(root,text="窗口置项",font=20,variable=v,command=Call_C_B)

d_selet.grid(row=4,columnspan=2)

root.mainloop()

阅读(1028) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~