|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是一个自动阅卷的小程序,部分代码如下
- def answer_qusetion():
- num = question_num.get()
- answer_root.destroy()
- if num <= 0:
- messagebox.showerror("Error","Not null")
- else:
- user_score = 0
- aq_root = Toplevel()
- aq_root.title("正在答题...")
- aq_root.iconbitmap('./img.ico')
- aq_root.geometry("600x400+450+300")
- # aq_root.resizable(FALSE, FALSE)
- # 获取excle中最大行,通过random(1,max_row)随机选择试题
- workbook = openpyxl.load_workbook('./题库.xlsx')
- worksheet = workbook.active
- max = worksheet.max_row
- x = random.randint(1, max)
- question_text = worksheet['A%d' % x].value
- option_A = worksheet['B%d' % x].value
- option_B = worksheet['C%d' % x].value
- option_C = worksheet['D%d' % x].value
- option_D = worksheet['E%d' % x].value
- right_answer = worksheet['F%d' % x].value
- Label(aq_root, text="%s"%question_text, font=('heiti', 12),wraplength=500,anchor=W, justify=LEFT).place(x=10, y=50)
- answer_var = StringVar()
- a1 = Radiobutton(aq_root, text='A: %s' % option_A, variable=answer_var, value='A').place(x=20, y=150)
- a2 = Radiobutton(aq_root, text='B: %s' % option_B, variable=answer_var, value='B').place(x=20, y=200)
- a3 = Radiobutton(aq_root, text='C: %s' % option_C, variable=answer_var, value='C').place(x=20, y=250)
- a4 = Radiobutton(aq_root, text='D: %s' % option_D, variable=answer_var, value='D').place(x=20, y=300)
- def next_question():
- aq_root.destroy()
- answer_qusetion()
- button_5 = Button(aq_root, text='下一题>>', bg="gray", width=20,
- command=next_question).place(x=400,y=350)
复制代码
num = question_num.get()接收了用户输入的题数,在这个函数里应该怎么写这个循环呢,当题数用尽就销毁窗口,显示成绩。这是代码最后一点了,也是最难的,实在想不出来了。。。
|
|