我做了一个答题程序
我想问下面这张图片中框起来的程序要怎样才能换成再下一张图片中的程序?(原本的程序是题目我需要自己一个个输进去,后面的程序可以从题库中随机抽题)
import tkinter
import tkinter.messagebox
import sqlite3
def lgsql(): # 链接数据库
entryname = varname.get()
entrypass = varpass.get()
conn = sqlite3.connect('users.sqlite')
SQL = "SELECT * FROM user WHERE name='%s'" % entryname
cur = conn.execute(SQL)
lst = cur.fetchall()
conn.commit()
if lst:
if entrypass == lst[0][3]:#什么意思来着的
tkinter.messagebox.showinfo('欢迎', '欢迎' + entryname + '! 您的成绩将计入您的账户')
else:
tkinter.messagebox.showerror('错误', '密码错误!')
else:
tkinter.messagebox.showerror('错误', '没有这个用户!')
conn.close()
def regist2(): # 注册 直接链接到数据库
entryname = varname.get()
entrypass = varpass.get()
conn = sqlite3.connect('users.sqlite')
SQL = ''' insert into user(name,true,false,passwd)
values('%s','%s','%s','%s')''' % (entryname, '', '', entrypass)
conn.execute(SQL)
tkinter.messagebox.showinfo('成功', '注册成功!')
conn.commit()
conn.close()
def question(event):
winnew = tkinter.Toplevel(root)
winnew.geometry("200x200+200+200")
winnew.title("选题窗口")
btnhaigui = tkinter.Button(winnew, text='海龟', width=8)
btnhaigui.place(x=20, y=20)
btnhaitun = tkinter.Button(winnew, text='海豚', width=8)
btnhaitun.place(x=120, y=20)
btnjingyu = tkinter.Button(winnew, text='鲸鱼', width=8)
btnjingyu.place(x=20, y=60)
btnshayu = tkinter.Button(winnew, text='鲨鱼', width=8)
btnshayu.place(x=120, y=60)
btnshuimu = tkinter.Button(winnew, text='水母', width=8)
btnshuimu.place(x=20, y=100)
btnxia = tkinter.Button(winnew, text='虾', width=8)
btnxia.place(x=120, y=100)
btclose = tkinter.Button(winnew, text="关闭页面", width=16, command=winnew.destroy)
btclose.place(x=40, y=140)
btnhaigui.bind("<Button-1>", haigui)
btnhaitun.bind("<Button-1>", haitun)
btnjingyu.bind("<Button-1>", jingyu)
btnshayu.bind("<Button-1>", shayu)
btnshuimu.bind("<Button-1>", shuimu)
btnxia.bind("<Button-1>", xia)
def haigui(event):
winnew1 = tkinter.Toplevel(root)
winnew1.geometry("800x400+200+200")
winnew1.title("海龟")
lbl11 = tkinter.Label(winnew1, text='1.龟类属于爬行动物,全世界种类很多,有400多种。这些龟仅有8种栖于海洋,称为海龟,下列哪些龟不是海龟()')
lbl11.place(x=20, y=20)
def showselect():
varlbl2.set(varR.get())
varR = tkinter.StringVar()
varR.set("Y")
r1 = tkinter.Radiobutton(winnew1, text="A. 玳瑁", value="A",variable=varR,command=showselect)
r1.place(x=40,y=70)
r2 = tkinter.Radiobutton(winnew1, text="B. 棱皮龟", value="B",variable=varR,command=showselect)
r2.place(x=200,y=70)
r3 = tkinter.Radiobutton(winnew1, text="C. 山龟", value="C",variable=varR,command=showselect)
r3.place(x=40,y=100)
r4 = tkinter.Radiobutton(winnew1, text="D. 俪龟", value="D",variable=varR,command=showselect)
r4.place(x=200,y=100)
lbl11 = tkinter.Label(winnew1, text="你选了:")
lbl11.place(x=40,y=250)
varlbl2=tkinter.StringVar()
lbl12 = tkinter.Label(winnew1,textvariable=varlbl2)
lbl12.place(x=100,y=250)
def answer():
if lbl12 == "C":#why??
tkinter.messagebox.showinfo('正确', '回答正确!')
else:
tkinter.messagebox.showerror('错误', '回答错误!')
btnanswer = tkinter.Button(winnew1,text="下一题",command=answer)
btnanswer.place(x=700,y=300)