python项目--打字测试系统V1.0

更多功能正在开发中。。。
代码就在下方,欢迎大家一起交流,共同进步。
python项目--打字测试系统V1.0_第1张图片
python项目--打字测试系统V1.0_第2张图片

import threading
from tkinter import *
from tkinter import scrolledtext, filedialog, ttk
import tkinter.messagebox
import shutil
from tkinter import messagebox
import os
import time

import GVL
import TK_B2_2

t1 = '人言师者,捧着一颗心来,不带半根草去,或许我们与教师的境界相距尚远,但那一颗满怀希望与热情的心是相似的。我们因爱心和奉献相遇,二十个日夜,我们浅尝为师之艰、生活之苦'
seep=0

def b1():
    root = Tk()
    root.title("打字测试系统")
    root.geometry('500x500')
    root.wm_attributes('-topmost', 1)  # 弹出窗口置顶

    def B_1():
        GVL.h=1
        y = threading.Thread(target=re3)
        y.start()
        r()
    def B_2():
        GVL.h=0
        tkinter.messagebox.showinfo('测试结果', '打字结果:{}个/分钟'.format(seep))


    Bt_1 = Button(root, text='开始计时', command=B_1, width=10, height=1)
    Bt_1.place(x=100, y=0)

    Bt_2 = Button(root, text='计时结束', command=B_2, width=10, height=1)
    Bt_2.place(x=300, y=0)

    Et_1 = Entry(root, width=30, font=("黑体", 14))
    Et_1.place(x=100, y=100)

    Et_2 = Entry(root, width=30, font=("黑体", 14))
    Et_2.place(x=100, y=150)

    Et_3 = Entry(root, width=30, font=("黑体", 14))
    Et_3.place(x=100, y=200)

    Et_4 = Entry(root, width=30, font=("黑体", 14))
    Et_4.place(x=100, y=250)

    def r():
        E1 = Et_1.get()
        E2 = Et_2.get()
        E3 = Et_3.get()
        E4 = Et_4.get()
        y1 = len(E1)
        y2 = len(E2)
        y3 = len(E3)
        y4 = len(E4)
        if GVL.Dz1==0:
            Et_1.focus_set()  # 将光标移动至该文本框
            Et_1['state'] = 'normal'
            Et_2['state'] = 'disable'
            Et_3['state'] = 'disable'
            Et_4['state'] = 'disable'
            for e in range(15):
                if y1 > 0 and e < y1:
                    if E1[e] == t1[e]:
                        LB = Label(root, text=t1[e], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=75)
                    else:
                        LB = Label(root, text=t1[e], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=75)
                else:
                    LB = Label(root, text=t1[e], font=("黑体", 13)).place(x=(100 + (20 * e)), y=75)
                    LB = Label(root, text=t1[e + 15], font=("黑体", 13)).place(x=(100 + (20 * e)), y=125)
                    LB = Label(root, text=t1[e + 30], font=("黑体", 13)).place(x=(100 + (20 * e)), y=175)
                    LB = Label(root, text=t1[e + 45], font=("黑体", 13)).place(x=(100 + (20 * e)), y=225)
                if y1==15 and E1==t1[0:15]:
                    Et_1['state'] = 'disable'
                    Et_2['state'] = 'normal'
                    GVL.Dz1 = 1
        elif GVL.Dz1==1:
            Et_2.focus_set()
            for e in range(15):
                if y2 > 0 and e < y2:
                    if E2[e] == t1[e + 15]:
                        LB = Label(root, text=t1[e + 15], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=125)
                    else:
                        LB = Label(root, text=t1[e + 15], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=125)
                if y2==15 and E2==t1[15:30]:
                    Et_2['state'] = 'disable'
                    Et_3['state'] = 'normal'
                    GVL.Dz1 = 2
        elif GVL.Dz1==2:
            Et_3.focus_set()
            for e in range(15):
                if y3 > 0 and e < y3:
                    if E3[e] == t1[e + 30]:
                        LB = Label(root, text=t1[e + 30], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=175)
                    else:
                        LB = Label(root, text=t1[e + 30], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=175)
                if y3==15 and E3==t1[30:45]:
                    Et_3['state'] = 'disable'
                    Et_4['state'] = 'normal'
                    GVL.Dz1 = 3
        elif GVL.Dz1==3:
            Et_4.focus_set()
            for e in range(15):
                if y4 > 0 and e < y4:
                    if E4[e] == t1[e + 45]:
                        LB = Label(root, text=t1[e + 45], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=225)
                    else:
                        LB = Label(root, text=t1[e + 45], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=225)
                if y4==15 and E4==t1[45:60]:
                    Et_4['state'] = 'disable'
                    GVL.Dz1 = 4
                    GVL.h = 0
                    tkinter.messagebox.showinfo('测试结果', '打字结果:{}个/分钟'.format(seep))
                    return
        time.sleep(0.2)
        if GVL.h==1:
            o= threading.Thread(target=r)
            o.start()

    def re3():
        global seep
        for i in range(1, 100, 1):
            if GVL.h == 1:
                y = Et_1.get()+Et_2.get()+Et_3.get()+Et_4.get()
                a = len(y)
                seep = int((int(a) / int(i)) * 60)
                #LB = Label(root, text=int(seep), font=("黑体", 13)).place(x=10, y=75)
                time.sleep(1)
            else:
                return
        tkinter.messagebox.showinfo('测试结果', '打字结果:{}个/分钟'.format(seep))


    root.mainloop()

b1()

V2.0

import threading
from tkinter import *
from tkinter import scrolledtext, filedialog, ttk
import tkinter.messagebox
import shutil
from tkinter import messagebox
import os
import time

import GVL
import TK_B2_2

t1 = '1111111111111112222222222222223333333333333334444444444444446555555555555555555'
seep=0

def b1():
    root = Tk()
    root.title("打字测试系统")
    root.geometry('500x500')
    root.wm_attributes('-topmost', 1)  # 弹出窗口置顶

    def B_1():
        GVL.h=1
        y = threading.Thread(target=re3)
        y.start()
        r()
    def B_2():
        GVL.h=0
        tkinter.messagebox.showinfo('测试结果', '打字结果:{}个/分钟'.format(seep))


    Bt_1 = Button(root, text='开始计时', command=B_1, width=10, height=1)
    Bt_1.place(x=100, y=0)

    Bt_2 = Button(root, text='计时结束', command=B_2, width=10, height=1)
    Bt_2.place(x=300, y=0)

    Et_1 = Entry(root, width=30, font=("黑体", 14))
    Et_1.place(x=100, y=100)

    Et_2 = Entry(root, width=30, font=("黑体", 14))
    Et_2.place(x=100, y=150)

    Et_3 = Entry(root, width=30, font=("黑体", 14))
    Et_3.place(x=100, y=200)

    Et_4 = Entry(root, width=30, font=("黑体", 14))
    Et_4.place(x=100, y=250)

    def r():
        E1 = Et_1.get()
        E2 = Et_2.get()
        E3 = Et_3.get()
        E4 = Et_4.get()
        y1 = len(E1)
        y2 = len(E2)
        y3 = len(E3)
        y4 = len(E4)
        if GVL.Dz1==0:
            Et_1.focus_set()  # 将光标移动至该文本框
            Et_1['state'] = 'normal'
            Et_2['state'] = 'disable'
            Et_3['state'] = 'disable'
            Et_4['state'] = 'disable'
            for e in range(15):
                if y1 > 0 and e < y1:
                    if E1[e] == t1[e]:
                        LB = Label(root, text=t1[e], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=75)
                    else:
                        LB = Label(root, text=t1[e], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=75)
                else:
                    LB = Label(root, text=t1[e + 0 + (GVL.Dz1 * 15)], font=("黑体", 13)).place(x=(100 + (20 * e)), y=75)
                    LB = Label(root, text=t1[e + 15 + (GVL.Dz1 * 15)], font=("黑体", 13)).place(x=(100 + (20 * e)), y=125)
                    LB = Label(root, text=t1[e + 30 + (GVL.Dz1 * 15)], font=("黑体", 13)).place(x=(100 + (20 * e)), y=175)
                    LB = Label(root, text=t1[e + 45 + (GVL.Dz1 * 15)], font=("黑体", 13)).place(x=(100 + (20 * e)), y=225)
                if y1>=15 and E1[0:15]==t1[0 + (GVL.Dz1 * 15):15 + (GVL.Dz1 * 15)]:
                    Et_1['state'] = 'disable'
                    Et_2['state'] = 'normal'
                    GVL.Dz1 = 1
        elif GVL.Dz1==1:
            Et_2.focus_set()
            for e in range(15):
                if y2 > 0 and e < y2:
                    if E2[e] == t1[e + 15]:
                        LB = Label(root, text=t1[e + 15], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=125)
                    else:
                        LB = Label(root, text=t1[e + 15], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=125)
                else:
                    LB = Label(root, text=t1[e + 15], font=("黑体", 13)).place(x=(100 + (20 * e)), y=125)
                if y2>=15 and E2[0:15]==t1[15:30]:
                    Et_2['state'] = 'disable'
                    Et_3['state'] = 'normal'
                    GVL.Dz1 = 2
        elif GVL.Dz1==2:
            Et_1['state'] = 'normal'
            Et_1.delete(0, END)
            Et_3.focus_set()
            for e in range(15):
                if y3 > 0 and e < y3:
                    if E3[e] == t1[e + 30]:
                        LB = Label(root, text=t1[e + 30], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=175)
                    else:
                        LB = Label(root, text=t1[e + 30], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=175)
                if y3>=15 and E3[0:15]==t1[30:45]:
                    Et_3['state'] = 'disable'
                    Et_4['state'] = 'normal'
                    GVL.Dz1 = 3
        elif GVL.Dz1==3:
            Et_4.focus_set()
            for e in range(15):
                if y4 > 0 and e < y4:
                    if E4[e] == t1[e + 45]:
                        LB = Label(root, text=t1[e + 45], font=("黑体", 13), fg='green').place(x=(100+(20 * e)), y=225)
                    else:
                        LB = Label(root, text=t1[e + 45], font=("黑体", 13), fg='red').place(x=(100+(20 * e)), y=225)
                if y4>=15 and E4[0:15]==t1[45:60]:
                    Et_4['state'] = 'disable'
                    GVL.Dz1 = 4
                    GVL.h = 0
                    tkinter.messagebox.showinfo('测试结果', '打字结果:{}个/分钟'.format(seep))
                    return
        time.sleep(0.2)
        if GVL.h==1:
            o= threading.Thread(target=r)
            o.start()

    def re3():
        global seep
        for i in range(1, 100, 1):
            if GVL.h == 1:
                y = Et_1.get()+Et_2.get()+Et_3.get()+Et_4.get()
                a = len(y)
                seep = int((int(a) / int(i)) * 60)
                #LB = Label(root, text=int(seep), font=("黑体", 13)).place(x=10, y=75)
                time.sleep(1)
            else:
                return
        tkinter.messagebox.showinfo('测试结果', '打字结果:{}个/分钟'.format(seep))


    root.mainloop()

b1()

你可能感兴趣的:(python模块)