周报13

电子算盘答题加强版
import tkinter
import time
import random
import tkinter.messagebox

def login_in():
global name
name = en.get()
if name == "":
name = "胡胜卫"
login.quit()


def click1(event):
r1 = ['', '2', '3', '4', '5']
r2 = ['6', '7', '8', '9', '10']
w = event.widget
name = str(w).split('.')[2]
num = name.split('n')[1]
if num in r1:
if w['bg'] == 'blue':
w['bg'] = 'white'
frame1.children['!button'+str(r1.index(num)+6)]['bg'] = 'blue'
elif num in r2:
if w['bg'] == 'blue':
w['bg'] = 'white'
# print(num)
# r1.index(num)
if r2.index(num)!=0:
frame1.children['!button'+str(r2.index(num)+1)]['bg'] = 'blue'
else:
frame1.children['!button']['bg'] = 'blue'


def click2(event):
r3 = ['11', '12', '13', '14', '15']
r4 = ['16', '17', '18', '19', '20']
r5 = ['21', '22', '23', '24', '25']
r6 = ['26', '27', '28', '29', '30']
r7 = ['31', '32', '33', '34', '35']
w = event.widget
name = str(w).split('.')[2]
num = int(name.split('n')[1])
if (num-1)//5==2 or (num-1)//5==6:
if (num-1)//5==2:
if frame1.children['!button' + str(num)]['bg'] == 'red':
if frame1.children['!button' + str(num+5)]['bg'] == 'white':
frame1.children['!button' + str(num)]['bg'] = 'white'
frame1.children['!button' + str(num + 5)]['bg'] = 'red'
else:
if frame1.children['!button' + str(num)]['bg'] == 'red':
if frame1.children['!button' + str(num-5)]['bg'] == 'white':
frame1.children['!button' + str(num)]['bg'] = 'white'
frame1.children['!button' + str(num - 5)]['bg'] = 'red'

else:
if frame1.children['!button'+str(num)]['bg'] == 'red':
if frame1.children['!button'+str(num-5)]['bg'] == 'white':
frame1.children['!button' + str(num)]['bg'] = 'white'
frame1.children['!button' + str(num-5)]['bg'] = 'red'
elif frame1.children['!button'+str(num+5)]['bg'] == 'white':
frame1.children['!button' + str(num)]['bg'] = 'white'
frame1.children['!button' + str(num + 5)]['bg'] = 'red'


def click3():
s = []
for i in range(1, 6):
t = []
for k in range(7):
n = i + 5*k
if n == 1:
if frame1.children['!button']['bg'] == 'blue' or frame1.children['!button']['bg'] == 'red':
t.append(1)
else:
t.append(0)
else:
if frame1.children['!button' + str(n)]['bg'] == 'blue' or frame1.children['!button' + str(n)]['bg'] == 'red':
t.append(1)
else:
t.append(0)
s.append(t)
print(s)
num = []
for i in s:
n = 0
for k in range(1, 7):
if k == 1:
n = i[k] * 5
else:
if i[k] == 1:
n = n + 1
else:
break
num.append(n)
print(num)
r = 0
for i in range(len(num)):
r = r + num[i] * pow(10, i)
global result
result.append(r)
print(result)


def click4():
a = random.randint(100, 1000)
b = random.randint(0, a)
c = random.randint(0, 1)
d=''
if c == 0:
d = str(a)+"+"+str(b)
if c == 1:
d = str(a)+"-"+str(b)
l = tkinter.Label(frame2, text="", font=('宋体', 40, 'bold'), width=20)
global number
l.place(x=0, y=number*80)
number = number+1
l['text'] = d+"="
global answer
answer.append(eval(d))
print(answer)

def click5():
n = 0
global answer
global result
for i in range(len(answer)):
if answer[i] == result[i]:
n = n+1
tkinter.messagebox.askokcancel("撒花撒!花!", "亲爱的"+name+"用户,您一共对了"+str(n)+"道题!")

def update():
now = time.strftime("%H:%M:%S")
window.title(now)
print(now)
window.after(100, update)


name = ""
number = 0
result = []
answer = []





login = tkinter.Tk()
login.title("用户登录")
en = tkinter.Entry(login, font=('黑体', 12))
en.grid(column=1, row=1)

button = tkinter.Button(login, text='登录', command=login_in)

button.grid(column=1, row=2)
login.mainloop()

window = tkinter.Tk()

window.title(name)
window.geometry('1000x500')
frame1 = tkinter.Frame(window, width=500, height=500, bg='green')
frame1.grid(column=0, row=0)
frame2 = tkinter.Frame(window, width=500, height=500, bg='yellow')
frame2.grid(column=1, row=0)


for i in range(2):
for k in range(5):
if i == 1:
b = tkinter.Button(frame1, text=str(i) + str(k), bd=4, width=12, height=3, bg='white')
b.bind("<Button-1>", click1)
b.grid(column=k, row=i)
else:
b = tkinter.Button(frame1, text=str(i) + str(k), bd=4, width=12, height=3, bg='blue')
b.bind("<Button-1>", click1)
b.grid(column=k, row=i)
for i in range(2, 7):
for k in range(5):
if i != 2:
b = tkinter.Button(frame1, text=str(i)+str(k), bd=4, width=12, height=3, bg='red')
b.bind("<Button-1>", click2)
b.grid(column=k, row=i)
else:
b = tkinter.Button(frame1, text=str(i) + str(k), bd=4, width=12, height=3, bg='white')
b.bind("<Button-1>", click2)
b.grid(column=k, row=i)
button2 = tkinter.Button(frame2, text="提交",command=click3)
button2.place(x=0, y=450)
button3 = tkinter.Button(frame2, text="下一题",command=click4)
button3.place(x=50, y=450)
button4 = tkinter.Button(frame2, text='开始', command=update)
button4.place(x=100, y=450)
button5 = tkinter.Button(frame2, text='得分', command=click5)
button5.place(x=150, y=450)

window.mainloop()
posted @ 2022-05-29 18:33  我的未来姓栗山  阅读(18)  评论(0编辑  收藏  举报