1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
| import tkinter as tk import xlrd import random import time from tkinter.messagebox import showinfo
window = tk.Tk() window.title('背单词') window.geometry('500x700')
l1 = tk.Label(window, text='请选择单词类型', bg='blue', font=('Arial', 12), width=15, height=2) l1.place(x=20,y=30)
n=10 num=0 cor=wro=0 _new_=1 _test_=0 def load(file_name): data = xlrd.open_workbook(file_name) table = data.sheet_by_name('Sheet1') words=table.col(0, start_rowx=0, end_rowx=None) words=[x.value for x in words] meaning=table.col(1, start_rowx=0, end_rowx=None) meaning=[x.value for x in meaning] global wordlist wordlist=[[a,b] for a,b in zip(words,meaning)] t1.delete('1.0','end') t1.insert('insert',file_name[0:4]) def newword(): global word global _test_ global _new_ global num global time_start global time_end if num==0: t4.delete('1.0','end') time_start=time.time() if num<n: if _new_==1: word=random.choice(wordlist) t2.delete('1.0','end') t5.delete('1.0','end') t6.delete('1.0','end') e.delete(0,'end') t2.insert('insert',word[1]) _new_=0 _test_=1 else: showinfo(title='提示', message='请输入答案并检验') else: t2.delete('1.0','end') t5.delete('1.0','end') t6.delete('1.0','end') t2.insert('insert','恭喜你背完了!点击检验查看正确率与时间') e.delete(0,'end') time_end=time.time() _new_=0 _test_=1 def test(): global _new_ global _test_ global num global cor global wro global time_end if num<n : if _test_==1: var=e.get() if var==word[0]: t5.insert('insert','√') cor+=1 else: t6.insert('insert','×') s=str(word[0]) t5.insert('1.0',s) wro+=1 num+=1 _new_=1 _test_=0 else: showinfo(title='提示', message='请点击新单词进行测试') else: t2.delete('1.0','end') t5.delete('1.0','end') t6.delete('1.0','end') t5.insert('insert',str(cor)) t6.insert('insert',str(wro)) t2.insert('insert','请点击新单词开始下一轮背诵') t4.insert('insert',str(time_end-time_start)[0:6]+'秒') _new_=1 _test_=0 num=cor=wro=0
def reset(): global wordlist global num global cor global wro global _new_ global _test_ global n t1.delete('1.0','end') t2.delete('1.0','end') t4.delete('1.0','end') t5.delete('1.0','end') t6.delete('1.0','end') t8.delete('1.0','end') e.delete(0,'end') e2.delete(0,'end') e3.delete(0,'end') wordlist=[] num=cor=wro=0 _new_=1 _test_=0 n=10
def search(): key=e3.get() t8.delete('1.0','end') flag=0 for x in wordlist: if x[0]==key: t8.insert('1.0',x[1]) flag=1 if flag==1: pass else: t8.insert('1.0','该字典没有相关释义,请更换字典')
def defnum(): global n n=int(e2.get())
def CET_4(): file_name='四级词汇.xls' load(file_name)
def CET_6(): file_name='六级词汇.xls' load(file_name)
def IELTS(): file_name='雅思词汇.xlsx' load(file_name)
def TOEFL(): file_name='托福词汇.xlsx' load(file_name)
t1=tk.Text(window,font=('Arial', 12),width=8,height=1) t1.place(x=200,y=40)
b1 = tk.Button(window, text='四级词汇', font=('Arial', 12), width=10, height=2, command=CET_4) b1.place(x=50,y=100)
b2 = tk.Button(window,text='六级词汇',font=('Arial', 12),width=10, height=2,command=CET_6) b2.place(x=150,y=100)
b3 = tk.Button(window,text='雅思词汇',font=('Arial', 12),width=10, height=2,command=IELTS) b3.place(x=250,y=100)
b4 = tk.Button(window,text='托福词汇',font=('Arial', 12),width=10, height=2,command=TOEFL) b4.place(x=350,y=100)
l2=tk.Label(window,text='词义:',font=('Arial', 12),width=6,height=2) l2.place(x=40,y=200)
t2=tk.Text(window,font=('Arial', 12),width=35,height=3) t2.place(x=100,y=195)
l3=tk.Label(window,text='单词:',font=('Arial', 12),width=6,height=2) l3.place(x=40,y=300)
e=tk.Entry(window,font=('Arial', 12),width=20) e.place(x=100,y=310)
b5=tk.Button(window,text='检验',font=('Arial', 12),width=5,height=1,command=test) b5.place(x=300,y=305)
b6=tk.Button(window,text='新单词',font=('Arial', 12),width=5,height=1,command=newword) b6.place(x=380,y=305)
l4=tk.Label(window,text='用时:',font=('Arial', 12),width=6,height=2) l4.place(x=40,y=500)
t4=tk.Text(window,font=('Arial', 12),width=15,height=1) t4.place(x=100,y=510)
l5=tk.Label(window,text='正确:',font=('Arial', 12),width=6,height=2) l5.place(x=40,y=400)
t5=tk.Text(window,font=('Arial', 12),width=15,height=1) t5.place(x=100,y=410)
l6=tk.Label(window,text='错误:',font=('Arial', 12),width=6,height=2) l6.place(x=250,y=400)
t6=tk.Text(window,font=('Arial', 12),width=10,height=1) t6.place(x=310,y=410)
b7=tk.Button(window,text='重置',font=('Arial', 12),width=5,height=1,command=reset) b7.place(x=300,y=505)
l7=tk.Label(window,text='背诵个数:',font=('Arial', 12),width=8,height=2) l7.place(x=320,y=30)
e2=tk.Entry(window,font=('Arial', 12),width=2) e2.place(x=400,y=40)
b8=tk.Button(window,text='确定',font=('Arial', 12),width=3,height=1,command=defnum) b8.place(x=430,y=35)
b9=tk.Button(window,text='搜索',font=('Arial', 12),width=3,height=1,command=search) b9.place(x=40,y=600)
e3=tk.Entry(window,font=('Arial', 12),width=15) e3.place(x=100,y=610)
l8=tk.Label(window,text='意思:',font=('Arial', 12),width=5,height=2) l8.place(x=260,y=550)
t8=tk.Text(window,font=('Arial', 12),width=18,height=3) t8.place(x=260,y=590)
window.mainloop()
|