背单词软件

        唉,这个软件的由来可谓是及其的离谱,因为快会考了,我们的班主任emmm,各位可以自己脑补,如今项目大体完工就来发一下

        当然大家也可以去作者的个人博客去看地址:澪的个人博客

        源码下载:yuanma.zip - 蓝奏云

        windows版(理论上兼容windows10及以上版本):windows.zip - 蓝奏云

        linux版(测试系统Ubuntu22.04.2):​​​​​​​linux.zip - 蓝奏云

        接下来是代码部分   ps:下面仅为代码部分如需完整文件请点击上面源码下载链接:

import tkinter as tk
import os
import random
from urllib import request, parse
import json
import tkinter.messagebox
import webbrowser
from PIL import Image, ImageTk
#from tkhtmlview import HTMLLabel
'''
from ttkbootstrap import Style
'''
from tkinter import ttk
import sys
import datetime
#sudo apt-get install espeak  ps:ubuntu系统需要先安装这个不然pyttsx3用不了
import pyttsx3
#加锁为True解锁为Flase
count_state = False
error_count = 0 
root = tk.Tk()
'''
style = Style(theme='darkly')
root = style.master
'''
root.resizable(False, False)
root.geometry('900x700+250+0')
root.title("背单词工具——一起背单词,一起向未来")

#root.iconbitmap('wushan\icon.ico')

#导入英文单词
try:
    classes_path = os.path.expanduser("wushan/ci")
    with open(classes_path,'r',encoding = 'UTF-8') as f:
        ci = f.readlines()
    ci = [c.strip() for c in ci]
except:
    classes_path = os.path.expanduser("wushan/ci")
    with open(classes_path,'r',encoding = 'gbk') as f:
        ci = f.readlines()
    ci = [c.strip() for c in ci]

#导入中文翻译
try:
    classes_path = os.path.expanduser("wushan/fanyi")
    with open(classes_path,'r',encoding = 'UTF-8') as f:
        fanyi = f.readlines()
    fanyi = [c.strip() for c in fanyi]
except:
    classes_path = os.path.expanduser("wushan/fanyi")
    with open(classes_path,'r',encoding = 'gbk') as f:
        fanyi = f.readlines()
    fanyi = [c.strip() for c in fanyi]








#提供给练习模式的一个新运行补丁
def xvanzeqi():
    window5 = tk.Tk()
    window5.resizable(False, False)
    window5.geometry('300x350+300+100')
    window5.title("范围选择器")
    #window5.iconbitmap('wushan\icon.ico')
    tk.Label(window5, text="请选择训练的部分").place(x=0,y=0,anchor='nw')
    tk.Button(window5,text="练习360词(会考5级词)", command=lambda:[qianbanbufen(),qbbfhs()]).place(x=0,y=35,anchor='nw')
    tk.Button(window5,text="练习640词(会考4级词)", command=lambda:[houbanbufen(),hbbfhs()]).place(x=0,y=70,anchor='nw')
    def qbbfhs():
        tk.Button(window5,text="练习360词(会考5级词)", command=lambda:[qianbanbufen()],state="disabled").place(x=0,y=35,anchor='nw')
        tk.Button(window5,text="练习640词(会考4级词)", command=lambda:[houbanbufen(),hbbfhs()]).place(x=0,y=70,anchor='nw')
    def hbbfhs():
        tk.Button(window5,text="练习640词(会考4级词)", command=lambda:[houbanbufen()],state="disabled").place(x=0,y=70,anchor='nw')
        tk.Button(window5,text="练习360词(会考5级词)", command=lambda:[qianbanbufen(),qbbfhs()]).place(x=0,y=35,anchor='nw')

    tk.Label(window5, text="请选择完360词或640词后\n在选择下拉框中的具体范围").place(x=0,y=105,anchor='nw')
    xVariable = tk.StringVar()
    com = ttk.Combobox(window5, textvariable=xVariable)
    com.pack(side="left")
    com["value"] = ("a", "b", "c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
    def xFunc(event):
        global user_choose
        user_choose=com.get()         
    com.bind("<<ComboboxSelected>>", xFunc)

    tk.Button(window5,text="确定", command=lambda:[fanwei(),qvci(),xvanxiang(),guanbi()]).place(x=0,y=200,anchor='nw')
    def fanwei():
        global resyw
        global zhongwen_liebiao
        try:
            test=user_choose
            resyw = [idx for idx in ci1 if idx[0].lower() == test.lower()]
        except:
            test=user_choose
            resyw = [idx for idx in ci2 if idx[0].lower() == test.lower()]
        fanyi_weilaide1=resyw[0]
        fanyi_weilaide2=resyw[-1]
        fanyi_shouci=ci.index(fanyi_weilaide1)
        fanyi_weici=ci.index(fanyi_weilaide2)
        fanyi_weici+=1
        zhongwen_liebiao=fanyi[fanyi_shouci:fanyi_weici]


    def qianbanbufen():
        global ci1
        ci1=ci[0:359]

    def houbanbufen():
        global ci2
        ci2=ci[359:999]


    def guanbi():
        window5.destroy()

    window5.mainloop()





def langdu():
    try:
        pyttsx3.speak(suiji)
    except:
        pyttsx3.speak("没有找到可以朗读的单词")	



#对随机到的词进行处理
def qvci():
    global zhongwen
    global suiji
    suiji=random.sample(resyw,1)
    suiji = "".join(suiji)
    tk.Label(root, text=suiji, fg="red", bg="deepskyblue",font=("楷体", 18, "underline")).place(x=200,y=0,width="500",anchor='nw')
    suiji0 = "".join(suiji)
    suiji0=resyw.index(suiji0)
    zhongwen=zhongwen_liebiao[suiji0]
    file_1=open("wushan/da",mode="w",encoding='utf-8')
    file_1.write(zhongwen)

    #tk.Button(root,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang(),lianxizongshu()],state="disabled").place(x=200,y=400,anchor='nw')
    tk.Button(root,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang()],state="disabled").place(x=350,y=400,anchor='nw')


#生成随即错误选项
def cuowuxvanxiang():
    global zw1
    global zw2
    global zw3
    global zw4
    global zw5

    suiji1=random.sample(zhongwen_liebiao,1)
    suiji1 = "".join(suiji1)
    suiji2=random.sample(zhongwen_liebiao,1)
    suiji2 = "".join(suiji2)
    suiji3=random.sample(zhongwen_liebiao,1)
    suiji3 = "".join(suiji3)
    suiji4=random.sample(zhongwen_liebiao,1)
    suiji4 = "".join(suiji4)

    danci=[]
    danci.append(suiji1)
    danci.append(suiji2)
    danci.append(suiji3)
    danci.append(suiji4)
    danci.append(zhongwen)
    danci=random.sample(danci,5)
    zw1=danci[0]
    zw2=danci[1]
    zw3=danci[2]
    zw4=danci[3]
    zw5=danci[4]


#选项
def xvanxiang():
    cuowuxvanxiang()
    #suijiweizhi() ps:以弃用
    tk.Button(root,text=zw3,width=20, height=2,command=lambda:[xvancuo1(),panduan()]).place(x=350,y=60,anchor='nw')
    tk.Button(root,text=zw1,width=20, height=2,command=lambda:[xvancuo2(),panduan()]).place(x=350,y=120,anchor='nw')
    tk.Button(root,text=zw2,width=20, height=2,command=lambda:[xvancuo3(),panduan()]).place(x=350,y=180,anchor='nw')
    tk.Button(root,text=zw5,width=20, height=2,command=lambda:[dui(),panduan()]).place(x=350,y=240,anchor='nw')
    tk.Button(root,text=zw4,width=20, height=2,command=lambda:[xvancuo4(),panduan()]).place(x=350,y=300,anchor='nw')
    #tk.Button(root,text="开始",command=lambda:[qvci(), xvanxiang(),lianxizongshu()],state="disabled").place(x=100,y=0,anchor='nw')
    tk.Button(root,text="重选范围",command=lambda:[xvanzeqi()]).place(x=100,y=0,anchor='nw')
#向文件写入用户选择
def dui():
    file_1=open("wushan/user",mode="w",encoding='utf-8')
    file_1.write(zw5)

def xvancuo1():
    file_1=open("wushan/user",mode="w",encoding='utf-8')
    file_1.write(zw3)

def xvancuo2():
    file_1=open("wushan/user",mode="w",encoding='utf-8')
    file_1.write(zw1)

def xvancuo3():
    file_1=open("wushan/user",mode="w",encoding='utf-8')
    file_1.write(zw2)

def xvancuo4():
    file_1=open("wushan/user",mode="w",encoding='utf-8')
    file_1.write(zw4)

#写入错题本
def ctb():
    file_1=open("wushan/ctb",mode="a",encoding='utf-8')
    file_1.write(suiji)
    file_1.write('\n')
    file_1=open("wushan/ctbzw",mode="a",encoding='utf-8')
    file_1.write(zhongwen)
    file_1.write('\n')
    tk.Button(root,text="加入错题本",width=20, height=2,command=lambda:[ctb()],state="disabled").place(x=350,y=400,anchor='nw')

#判断
def panduan():
    try:
        classes_path = os.path.expanduser("wushan/da")
        with open(classes_path,'r',encoding = 'UTF-8') as f:
            pd = f.readlines()
        pd = [c.strip() for c in pd]
    except:
        classes_path = os.path.expanduser("wushan/da")
        with open(classes_path,'r',encoding = 'gbk') as f:
            pd = f.readlines()
        pd = [c.strip() for c in pd]

    try:
        classes_path = os.path.expanduser("wushan/user")
        with open(classes_path,'r',encoding = 'UTF-8') as f:
            user = f.readlines()
        user = [c.strip() for c in user]
    except:
        classes_path = os.path.expanduser("wushan/user")
        with open(classes_path,'r',encoding = 'gbk') as f:
            user = f.readlines()
        user = [c.strip() for c in user]

    if user == pd:
        tk.Label(root, text="选择正确,请单击下一题", fg="red", bg="deepskyblue",font=("楷体", 18, "underline")).place(x=200,y=0,width="500",anchor='nw')
        #tk.Button(root,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang(),lianxizongshu(),qinglizaxiang()]).place(x=200,y=400,anchor='nw')
        tk.Button(root,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang(),qinglizaxiang()]).place(x=350,y=400,anchor='nw')
        try:
            classes_path = os.path.expanduser("wushan/cuowu")
            with open(classes_path,'r',encoding = 'UTF-8') as f:
                user55 = f.readlines()
            user55 = [c.strip() for c in user55]
        except:
            classes_path = os.path.expanduser("wushan/cuowu")
            with open(classes_path,'r',encoding = 'gbk') as f:
                user55 = f.readlines()
            user55 = [c.strip() for c in user55]

        if "cuo" in user55:
            print("1")
        else:
            file_1=open("wushan/zhengque",mode="a",encoding='utf-8')
            file_1.write("dui")
            file_1.write('\n')

    else:
        xiaochuli="错误!"+suiji
        tk.Label(root, text=xiaochuli, fg="red", bg="deepskyblue",font=("楷体", 18, "underline")).place(x=200,y=0,width="500",anchor='nw')
        tk.Button(root,text="加入错题本",width=20, height=2,command=lambda:[ctb()]).place(x=350,y=400,anchor='nw')
        file_1=open("wushan/cuowu",mode="a",encoding='utf-8')
        file_1.write("cuo")
        file_1.write('\n')
        

        
def guanyv():
    window = tk.Tk()
    window.resizable(False, False)
    #window.iconbitmap('wushan\icon.ico')
    window.geometry('400x200+350+0')
    window.title("关于")
    tk.Label(window, text="持续开发中").pack()
    tk.Label(window, text="指导教师:葛久平").pack()
    tk.Label(window, text="制作人:宋勃逸").pack()
    tk.Label(window, text="社团:飞翔100").pack()
    tk.Label(window, text="开源地址:https://www.ling2023.xyz/ym/bdc.html").pack()
    tk.Button(window,text="点击跳转",command=lambda:[tiaozhuan()]).pack()
    tk.Label(window, text="版本号:2.3").pack()
    def tiaozhuan():
        webbrowser.open_new_tab('https://www.ling2023.xyz/ym/bdc.html')

    #html=HTMLLabel(window, html='<a href="https://www.ling2023.xyz/">网站:https://www.ling2023.xyz/</a>').place(x=70,y=80)
    window.mainloop()





def qclsjlzc():
    with open(r'wushan/lishi','a+',encoding='utf-8') as test:
        test.truncate(0)






#自测模块的补充功能
def user_lishijilu():
    window = tk.Tk()
    window.resizable(False, False)
    #window.iconbitmap('wushan\icon.ico')
    window.geometry('500x300+350+0')
    window.title("历史记录")
    try:
        classes_path = os.path.expanduser("wushan/lishi")
        with open(classes_path,'r',encoding = 'UTF-8') as f:
            lsjl = f.readlines()
        lsjl = [c.strip() for c in lsjl]
    except:
        classes_path = os.path.expanduser("wushan/lishi")
        with open(classes_path,'r',encoding = 'gbk') as f:
            lsjl = f.readlines()
        lsjl = [c.strip() for c in lsjl]
    listbox = tk.Listbox(window,width=50, height=10,selectmode='multiple')
    for item in lsjl:
        listbox.insert('end',item)
    listbox.place(x=0,y=0,anchor='nw')
    tk.Button(window,text="清除历史记录",command=lambda:[qclsjlzc(),bh()]).place(x=0,y=250,anchor='nw')
    def bh():
        tk.Button(window,text="清除历史记录",command=lambda:[qclsjlzc()],state="disabled").place(x=0,y=250,anchor='nw')
        tk.Label(window, text="清除历史记录后不会立刻刷新,\n关闭历史记录窗口在打开才会刷新").place(x=120,y=245,anchor='nw')
    window.mainloop()



#自测模式
def zicimoshi():
    global error_count
    error_count=0
    window1 = tk.Tk()
    window1.resizable(False, False)
    window1.geometry('880x680+350+50')
    #window1.iconbitmap('wushan\icon.ico')
    window1.title("检测模块——一起背单词,一起向未来")
    with open(r'wushan/jsq','a+',encoding='utf-8') as test:
        test.truncate(0)
    try:
        classes_path = os.path.expanduser("wushan/ci")
        with open(classes_path,'r',encoding = 'UTF-8') as f:
            ci = f.readlines()
        ci = [c.strip() for c in ci]
    except:
        classes_path = os.path.expanduser("wushan/ci")
        with open(classes_path,'r',encoding = 'gbk') as f:
            ci = f.readlines()
        ci = [c.strip() for c in ci]

    #导入中文翻译
    try:
        classes_path = os.path.expanduser("wushan/fanyi")
        with open(classes_path,'r',encoding = 'UTF-8') as f:
            fanyi = f.readlines()
        fanyi = [c.strip() for c in fanyi]
    except:
        classes_path = os.path.expanduser("wushan/fanyi")
        with open(classes_path,'r',encoding = 'gbk') as f:
            fanyi = f.readlines()
        fanyi = [c.strip() for c in fanyi]



    #对随机到的词进行处理
    def qvci():
        global zhongwenjc
        global suijijc
        suijijc=random.sample(ci,1)
        suijijc = "".join(suijijc)
        tk.Label(window1, text=suijijc, fg="red", bg="deepskyblue",font=("楷体", 18, "underline")).place(x=200,y=0,width="500",anchor='nw')
        suiji0 = "".join(suijijc)
        suiji0=ci.index(suiji0)
        zhongwenjc=fanyi[suiji0]
        file_1=open("wushan/dazc",mode="w",encoding='utf-8')
        file_1.write(zhongwenjc)

        #tk.Button(window1,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang(),lianxizongshu()],state="disabled").place(x=200,y=400,anchor='nw')
        #tk.Button(window1,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang()],state="disabled").place(x=200,y=400,anchor='nw')

    #生成随即错误选项
    def cuowuxvanxiang():
        try:
            classes_path = os.path.expanduser("wushan/jsq")
            with open(classes_path,'r',encoding = 'UTF-8') as f:
                userjc = f.readlines()
            userjc = [c.strip() for c in userjc]
        except:
            classes_path = os.path.expanduser("wushan/jsq")
            with open(classes_path,'r',encoding = 'gbk') as f:
                userjc = f.readlines()
            userjc = [c.strip() for c in userjc]
        userjc1=len(userjc)
        if userjc1<lxsjc:
            global zw1zc
            global zw2zc
            global zw3zc
            global zw4zc
            global zw5zc
            
            suiji1=random.sample(fanyi,1)
            suiji1 = "".join(suiji1)
            suiji2=random.sample(fanyi,1)
            suiji2 = "".join(suiji2)
            suiji3=random.sample(fanyi,1)
            suiji3 = "".join(suiji3)
            suiji4=random.sample(fanyi,1)
            suiji4 = "".join(suiji4)
            danci=[]
            danci.append(suiji1)
            danci.append(suiji2)
            danci.append(suiji3)
            danci.append(suiji4)
            danci.append(zhongwenjc)
            danci=random.sample(danci,5)
            zw1zc=danci[0]
            zw2zc=danci[1]
            zw3zc=danci[2]
            zw4zc=danci[3]
            zw5zc=danci[4]
        else:
            zhengque=lxsjc-error_count
            tk.Label(window1, text="选择正确——检测结束", fg="red", bg="deepskyblue",font=("楷体", 18, "underline")).place(x=200,y=0,width="500",anchor='nw')
            dangqianshijian=datetime.datetime.now().strftime('%Y-%m-%d  %H:%M:%S')
            lishijilu=dangqianshijian+"-----"+str(zhengque/lxsjc*100)+"%"
            #记录一个小BUG只有按下下面的按钮才会写入文件,但写入文件按照逻辑应该先执行     测试环境:python版本:3.10.6 64位   编译器:vscode   系统:Ubuntu22.04.2
            file_1=open("wushan/lishi",mode="a",encoding='utf-8')
            file_1.write(lishijilu)
            file_1.write('\n')
            tk.Button(window1,text="完结撒花!",width=20, height=2,command=lambda:[xvancuo1(),panduan()],state="disabled").place(x=350,y=60,anchor='nw')
            tk.Button(window1,text="完结撒花!!",width=20, height=2,command=lambda:[xvancuo2(),panduan()],state="disabled").place(x=350,y=120,anchor='nw')
            tk.Button(window1,text="完结撒花!!!",width=20, height=2,command=lambda:[xvancuo3(),panduan()],state="disabled").place(x=350,y=180,anchor='nw')
            tk.Button(window1,text="完结撒花!!!!",width=20, height=2,command=lambda:[dui(),panduan()],state="disabled").place(x=350,y=240,anchor='nw')
            tk.Button(window1,text="完结撒花!!!!!",width=20, height=2,command=lambda:[xvancuo4(),panduan()],state="disabled").place(x=350,y=300,anchor='nw')
            tanchutext='本次检测共:'+str(lxsjc)+"\n"+"错误数量为:"+str(error_count)+"\n"+"正确数量为:"+str(zhengque)+"\n"+"点击确定后会记录本次检测记录,以后可点击记录按钮查看"
            tkinter.messagebox.showinfo(title = '提示',message=tanchutext)
            tk.Button(window1,text="完结撒花!",width=20, height=2,command=lambda:[xvancuo1()],state="disabled").place(x=350,y=60,anchor='nw')
            tk.Button(window1,text="完结撒花!!",width=20, height=2,command=lambda:[xvancuo2()],state="disabled").place(x=350,y=120,anchor='nw')
            tk.Button(window1,text="完结撒花!!!",width=20, height=2,command=lambda:[panduan()],state="disabled").place(x=350,y=180,anchor='nw')
            tk.Button(window1,text="完结撒花!!!!",width=20, height=2,command=lambda:[panduan()],state="disabled").place(x=350,y=240,anchor='nw')
            tk.Button(window1,text="完结撒花!!!!!",width=20, height=2,command=lambda:[panduan()],state="disabled").place(x=350,y=300,anchor='nw')
    #选项
    def xvanxiang():
        cuowuxvanxiang()
        #suijiweizhi() ps:已弃用
        tk.Button(window1,text=zw3zc,width=20, height=2,command=lambda:[xvancuo1(),panduan()]).place(x=350,y=60,anchor='nw')
        tk.Button(window1,text=zw1zc,width=20, height=2,command=lambda:[xvancuo2(),panduan()]).place(x=350,y=120,anchor='nw')
        tk.Button(window1,text=zw2zc,width=20, height=2,command=lambda:[xvancuo3(),panduan()]).place(x=350,y=180,anchor='nw')
        tk.Button(window1,text=zw5zc,width=20, height=2,command=lambda:[dui(),panduan()]).place(x=350,y=240,anchor='nw')
        tk.Button(window1,text=zw4zc,width=20, height=2,command=lambda:[xvancuo4(),panduan()]).place(x=350,y=300,anchor='nw')
        tk.Button(window1,text="确定",command=lambda:[qvci(), xvanxiang()],state="disabled").place(x=0,y=60,anchor='nw')
    #向文件写入用户选择
    def dui():
        file_1=open("wushan/userzc",mode="w",encoding='utf-8')
        file_1.write(zw5zc)

    def xvancuo1():
        file_1=open("wushan/userzc",mode="w",encoding='utf-8')
        file_1.write(zw3zc)

    def xvancuo2():
        file_1=open("wushan/userzc",mode="w",encoding='utf-8')
        file_1.write(zw1zc)

    def xvancuo3():
        file_1=open("wushan/userzc",mode="w",encoding='utf-8')
        file_1.write(zw2zc)

    def xvancuo4():
        file_1=open("wushan/userzc",mode="w",encoding='utf-8')
        file_1.write(zw4zc)


    #判断
    def panduan():
        global count_state#函数声明好全局变量,状态和错误数量,方便错误数量本地存储和读取
        global error_count
        try:
            classes_path = os.path.expanduser("wushan/dazc")
            with open(classes_path,'r',encoding = 'UTF-8') as f:
                pd = f.readlines()
            pd = [c.strip() for c in pd]
        except:
            classes_path = os.path.expanduser("wushan/dazc")
            with open(classes_path,'r',encoding = 'gbk') as f:
                pd = f.readlines()
            pd = [c.strip() for c in pd]

        try:
            classes_path = os.path.expanduser("wushan/userzc")
            with open(classes_path,'r',encoding = 'UTF-8') as f:
                user = f.readlines()
            user = [c.strip() for c in user]
        except:
            classes_path = os.path.expanduser("wushan/userzc")
            with open(classes_path,'r',encoding = 'gbk') as f:
                user = f.readlines()
            user = [c.strip() for c in user]


        if user == pd:

            tk.Label(window1, text="选择正确", fg="red", bg="deepskyblue",font=("楷体", 18, "underline")).place(x=200,y=0,width="500",anchor='nw')
            #tk.Button(window1,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang(),lianxizongshu(),qinglizaxiang()]).place(x=200,y=400,anchor='nw')
            #tk.Button(window1,text="下一题",width=20, height=2,command=lambda:[qvci(), xvanxiang(),jishuqi()]).place(x=200,y=400,anchor='nw')
            qvci()
            xvanxiang()
            jishuqi()
            count_state = False#因为已经正确,打为开锁状态,准备下一次错误后加锁

        else:
            if count_state==False:#如果状态等于False,False代表开锁状态
                error_count += 1#错误数量自增
                count_state=True #注意检查等于号数量,状态打为True(加锁状态),防止重复计算

            xiaochuli="错误!"+suijijc
            tk.Label(window1, text=xiaochuli, fg="red", bg="deepskyblue",font=("楷体", 18, "underline")).place(x=200,y=0,width="500",anchor='nw')
            tk.Label(window1, text="本次练习共:" +str(lxsjc)+"道").place(x=350,y=470,width="200",anchor='nw')
            tk.Label(window1, text="错误数量:" +str(error_count)).place(x=350,y=500,width="200",anchor='nw')


    def jishuqi():
        file_1=open("wushan/jsq",mode="a",encoding='utf-8')
        file_1.write("jishu")
        file_1.write('\n')


    def lianxishu():
        global lxsjc
        lxs=entry.get()
        lxsjc=int(lxs)
        qvci()
        xvanxiang()

    tk.Label(window1, text="指导教师:葛久平").place(x=750,y=600,anchor='nw')
    tk.Label(window1, text="制作人:宋勃逸").place(x=750,y=620,anchor='nw')
    tk.Label(window1, text="社团:飞翔100").place(x=750,y=640,anchor='nw')
    tk.Label(window1, text="请输入练习数量然后点击确定", fg="red", bg="deepskyblue").place(x=0,y=0,anchor='nw')
    entry = tk.Entry(window1,width=20)
    entry.place(x=0,y=30,anchor='nw')
    tk.Button(window1,text="确定",command=lambda:[lianxishu(),jishuqi()]).place(x=0,y=60,anchor='nw')
    tk.Button(window1,text="重来",command=lambda:[guanbi(),cqzicimoshi()]).place(x=0,y=95,anchor='nw')
    tk.Button(window1,text="历史",command=lambda:[user_lishijilu()]).place(x=0,y=130,anchor='nw')
    
    def guanbi():
        window1.destroy()

    window1.mainloop()


def cqzicimoshi():
    
    zicimoshi()




#翻译模块
def youdaofanyi():
    window = tk.Tk()
    window.resizable(False, False)
    #window.iconbitmap('wushan\icon.ico')
    window.geometry('500x500+350+0')
    window.title("翻译模块")
    entry = tk.Entry(window,width=20)
    entry.place(x=0,y=5,anchor='nw')
    def dedao():
        a=entry.get()
        def fy(i):
            req_url = 'http://fanyi.youdao.com/translate'  # 创建连接接口
            # 创建要提交的数据
            Form_Date = {}
            Form_Date['i'] = i
            Form_Date['doctype'] = 'json'
            Form_Date['form'] = 'AUTO'
            Form_Date['to'] = 'AUTO'
            Form_Date['smartresult'] = 'dict'
            Form_Date['client'] = 'fanyideskweb'
            Form_Date['salt'] = '1526995097962'
            Form_Date['sign'] = '8e4c4765b52229e1f3ad2e633af89c76'
            Form_Date['version'] = '2.1'
            Form_Date['keyform'] = 'fanyi.web'
            Form_Date['action'] = 'FY_BY_REALTIME'
            Form_Date['typoResult'] = 'false'
        
            data = parse.urlencode(Form_Date).encode('utf-8')
            response = request.urlopen(req_url, data)
            html = response.read().decode('utf-8')
            translate_results = json.loads(html)
            translate_results = translate_results['translateResult'][0][0]['tgt']
            return translate_results;  
        res = fy(a)
        text = tk.Text(window, width=40, height=10)
        text.place(x=0,y=80,anchor='nw')
        text.insert("1.0",res)

    tk.Button(window,text='翻译',command=dedao).place(x=180,y=0,anchor='nw')
    window.mainloop()



def qingchucuoti():
    with open(r'wushan/ctb','a+',encoding='utf-8') as test:
        test.truncate(0)
    with open(r'wushan/ctbzw','a+',encoding='utf-8') as test:
        test.truncate(0)


def qinglizaxiang():
    with open(r'wushan/cuowu','a+',encoding='utf-8') as test:
        test.truncate(0)


#错题练习
def cuotilianxi():
    window = tk.Tk()
    window.resizable(False, False)
    #window.iconbitmap('wushan\icon.ico')
    window.geometry('400x400+350+0')
    window.title("错题练习")
    try:
        classes_path = os.path.expanduser("wushan/ctb")
        with open(classes_path,'r',encoding = 'UTF-8') as f:
            pd = f.readlines()
        pd = [c.strip() for c in pd]
    except:
        classes_path = os.path.expanduser("wushan/ctb")
        with open(classes_path,'r',encoding = 'gbk') as f:
            pd = f.readlines()
        pd = [c.strip() for c in pd]
    try:
        classes_path = os.path.expanduser("wushan/ctbzw")
        with open(classes_path,'r',encoding = 'UTF-8') as f:
            user = f.readlines()
        user = [c.strip() for c in user]
    except:
        classes_path = os.path.expanduser("wushan/ctbzw")
        with open(classes_path,'r',encoding = 'gbk') as f:
            user = f.readlines()
        user = [c.strip() for c in user]    
    listbox = tk.Listbox(window,selectmode='multiple')
    for item in pd:
        listbox.insert('end',item)
    listbox.pack(side="left")

    listbox = tk.Listbox(window,selectmode='multiple')
    for item in user:
        listbox.insert('end',item)
    listbox.pack(side="left")
    tk.Label(window, text="在这里查看错题,弄会后可以点击清除记录按钮\n点击清除记录按钮后,重新打开错题本才会刷新").place(x=0,y=30,anchor='nw')
    tk.Button(window,text="清除记录",command=lambda:[qingchucuoti()]).place(x=120,y=320)
    window.mainloop()

def tuichu():
    for x in range(5):
        sys.exit()


#tk.Button(root,text="开始",command=lambda:[qvci(), xvanxiang(),lianxizongshu()]).place(x=100,y=0,anchor='nw')
tk.Label(root, text="指导教师:葛久平").place(x=750,y=600,anchor='nw')
tk.Label(root, text="制作人:宋勃逸").place(x=750,y=620,anchor='nw')
tk.Label(root, text="社团:飞翔100").place(x=750,y=640,anchor='nw')
tk.Button(root,text="练习模式",command=lambda:[xvanzeqi()]).place(x=100,y=0,anchor='nw')
tk.Button(root,text="测验模式",command=lambda:[zicimoshi()]).place(x=100,y=35,anchor='nw')
tk.Label(root, text="点击下面小喇叭可以朗读单词").place(x=705,y=40,anchor='nw')
tupian = tk.PhotoImage(file='wushan/1.png') 
tk.Button(root,image=tupian,text="朗读",command=lambda:[langdu()]).place(x=760,y=65,anchor='nw')
tk.Button(root,text="退出",command=lambda:[tuichu()]).place(x=100,y=70,anchor='nw')
tk.Button(root,text='查看错题',command=lambda:[cuotilianxi()]).place(x=760,y=0,anchor='nw')
tk.Button(root,text='关于',command=lambda:[guanyv()]).place(x=840,y=0,anchor='nw')
tk.Button(root,text='翻译',command=lambda:[youdaofanyi()]).place(x=705,y=0,anchor='nw')
root.mainloop()

欢迎大家在评论区讨论或指出问题

也可以通过邮箱联系作者

邮箱:official@ling2023.xyz

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lingview

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值