问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
from tkinter import *
import random as r
import os
xs=['赵','钱','孙','李','周','吴','郑','王','冯','陈','楮','卫','蒋','沈','韩','杨','朱','秦','尤','许','何','吕','施','张','孔','曹','严','华','金','魏','陶','姜','江','谢']
mz=['涛','昌','进','林','有','坚','和','彪','博','诚','先','敬','震','振','壮','会','群','豪','心','邦','承','乐','绍','功','松','善','厚','庆','磊','民','友','裕','河','哲'
,'江','超','浩','亮','政','谦','亨','奇','固','之','轮','翰','朗','伯','宏','言','若','鸣','朋','斌','梁','栋','维','启','克','伦','翔','旭','鹏','泽','晨','辰','士','以'
,'建','家','致','树','炎','德','行','时','泰','盛','雄','琛','钧','冠','策','腾','伟','刚','勇','毅','俊','峰','强','军','平','保','东','文','辉','力','明','永','健'
,'世','广','志','义','兴','良','海','山','仁','波','宁','贵','福','生','龙','元','全','国','胜','学','祥','才','发','成','康','星','光','天','达','安','岩','中','茂','武'
,'新','利','清','飞','彬','富','顺','信','子','杰','楠','榕','风','航','弘','占','建','剑']
def KS():
def KJKS():
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
global gan1,ys,gl
xm=xs[r.randint(0,33)]
for i in range(r.randint(1,2)):
xm+=mz[r.randint(0,152)]
nl=r.randint(25,88)
zl=r.randint(gl,100)
wl=r.randint(gl,100)
pd=r.randint(gl,100)
while True:
wl=r.randint(11,100)
if (wl-40)<=zl<=(wl+40):
break
s1=[xm,nl,zl,wl,pd]
if zl==100 or wl==100 or pd==100:
ys='red'
elif zl>=80 and wl>=80 and pd>=80:
ys='blue'
else:
ys='black'
for i in range(5):
lj='C:\\zhwj\\科举考试\\'+s[i]+'.txt'
with open(lj,'a+') as gan2:
gan2.write(str(s1[i])+',')
gan1=('姓名:{} 年龄:{} 智力:{} 武力:{} 品德:{}'.format(xm,nl,zl,wl,pd))
global top
top=Tk()
top.title("科举考试")
top.geometry("300x200+0+50")
global ks,gl
gl=10
ks=0
def jxkj():
def LQ1():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[0])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
d1.config(state=DISABLED)
def LQ2():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[1])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ3():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[2])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ4():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[3])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ5():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[4])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ6():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[5])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ7():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[6])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ8():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[7])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ9():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[8])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ10():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[9])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ11():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[10])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ12():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[11])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ13():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[12])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ14():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[13])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ15():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[14])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ16():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[15])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ17():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[16])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ18():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[17])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ19():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[18])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
def LQ20():
lqmd=[]
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
s1=['xm','nl','zl','wl','pd']
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s[i]+'.txt','r') as gan2:
dq=(gan2.read()).split(',')
lqmd.append(dq[19])
for i in range(5):
with open('C:\\zhwj\\科举考试\\'+s1[i]+'.txt','a+') as gan2:
gan2.write(str(lqmd[i])+',')
global ks,gan
s=['xmhc','nlhc','zlhc','wlhc','pdhc']
for i in range(5):
lj='C:\\zhwj\\科举考试\\'+s[i]+'.txt'
gan3=open(lj,'w')
gan3.close()
if ks==1:
ks=0
gan.destroy()
gan=Tk()
gan.title("科举考试")
gan.geometry("670x500+350+100")
c=Label(gan,text='科举考试名单').grid(row=0,column=3)
x=1
for i in range(10):
KJKS()
b=Label(gan,text=gan1,fg=ys).grid(row=x,column=1,sticky='W')
x+=1
x=1
global d1
for i in range(10):
d1=Button(gan,text='录取',command=LQ1,state=NORMAL).grid(row=1,column=2)
d2=Button(gan,text='录取',command=LQ2,state=NORMAL).grid(row=2,column=2)
d3=Button(gan,text='录取',command=LQ3,state=NORMAL).grid(row=3,column=2)
d4=Button(gan,text='录取',command=LQ4,state=NORMAL).grid(row=4,column=2)
d2=Button(gan,text='录取',command=LQ5,state=NORMAL).grid(row=5,column=2)
d6=Button(gan,text='录取',command=LQ6,state=NORMAL).grid(row=6,column=2)
d7=Button(gan,text='录取',command=LQ7,state=NORMAL).grid(row=7,column=2)
d8=Button(gan,text='录取',command=LQ8,state=NORMAL).grid(row=8,column=2)
d9=Button(gan,text='录取',command=LQ9,state=NORMAL).grid(row=9,column=2)
d10=Button(gan,text='录取',command=LQ10,state=NORMAL).grid(row=10,column=2)
x+=1
x=1
for i in range(10):
b=Label(gan,text='| ').grid(row=x,column=3)
x+=1
x=1
for i in range(10):
KJKS()
b=Label(gan,text=gan1,fg=ys).grid(row=x,column=4,sticky='W')
x+=1
ks=1
x=1
for i in range(10):
e1=Button(gan,text='录取',command=LQ11,state=NORMAL).grid(row=1,column=5)
e2=Button(gan,text='录取',command=LQ12,state=NORMAL).grid(row=2,column=5)
e3=Button(gan,text='录取',command=LQ13,state=NORMAL).grid(row=3,column=5)
e4=Button(gan,text='录取',command=LQ14,state=NORMAL).grid(row=4,column=5)
e5=Button(gan,text='录取',command=LQ15,state=NORMAL).grid(row=5,column=5)
e6=Button(gan,text='录取',command=LQ16,state=NORMAL).grid(row=6,column=5)
e7=Button(gan,text='录取',command=LQ17,state=NORMAL).grid(row=7,column=5)
e8=Button(gan,text='录取',command=LQ18,state=NORMAL).grid(row=8,column=5)
e9=Button(gan,text='录取',command=LQ19,state=NORMAL).grid(row=9,column=5)
e10=Button(gan,text='录取',command=LQ20,state=NORMAL).grid(row=10,column=5)
x+=1
def tsgl():
global gl
if gl<=10:
gl+=10
e.config(text="资助科举")
elif gl<=20:
gl+=10
e.config(text="建造寒士阁")
elif gl<=30:
gl+=10
e.config(text="建造太学院")
elif gl<=40:
gl+=10
e.config(text="建造京师大学堂")
elif gl<=50:
e.config(text="所有建筑建造完毕")
def tc():
global top,gan,ks
if ks==1:
gan.destroy()
top.destroy()
def xsgy():
s=['xm','nl','zl','wl','pd']
ckgy=Tk()
ckgy.geometry("240x500+350+100")
ckgy.title('查看官员')
Label(ckgy,text='姓名 ').grid(row=0,column=0)
Label(ckgy,text='年龄 ').grid(row=0,column=1)
Label(ckgy,text='智力 ').grid(row=0,column=2)
Label(ckgy,text='武力 ').grid(row=0,column=3)
Label(ckgy,text='品德 ').grid(row=0,column=4)
wai=0
for i in s:
li=1
with open('C:\\zhwj\\科举考试\\'+i+'.txt','r') as gan3:
dq=gan3.read()
dq1=dq.split(',')
for x in dq1:
Label(ckgy,text=x).grid(row=li,column=wai)
li+=1
wai+=1
def czgy():
s=['xm','nl','zl','wl','pd']
for i in s:
ab=open('C:\\zhwj\\科举考试\\'+i+'.txt','w')
ab.close()
d=Button(top,text='开始考试',command=jxkj)
d.place(x=150,y=60)
e=Button(top,text='提升概率',command=tsgl)
e.place(x=20,y=60)
ck=Button(top,text='查看官员',command=xsgy)
ck.place(x=20,y=120)
cz=Button(top,text='重置官员',command=czgy)
cz.place(x=150,y=120)
f=Button(top,text='退出',command=tc)
f.place(x=250,y=120)
top.mainloop()
if os.path.exists('C:\\zhwj'):
if os.path.exists('C:\\zhwj\\科举考试'):
KS()
else:
os.chdir('C:\\zhwj')
os.mkdir('科举考试')
os.chdir('C:\\zhwj\\科举考试')
s=['nlhc','zlhc','wlhc','pdhc','nl','zl','wl','pd','xm','xmhc']
s1='.txt'
for i in range(10):
ab=open(s[i]+s1,'w')
ab.close()
KS()
else:
os.chdir('C:\\')
os.mkdir('zhwj')
os.chdir('C:\\zhwj')
os.mkdir('科举考试')
os.chdir('C:\\zhwj\\科举考试')
s=['nl','zl','wl','pd','nlhc','zlhc','wlhc','pdhc','xm','xmhc']
s1='.txt'
for i in range(10):
ab=open(s[i]+s1,'w')
ab.close()
KS()
运行结果及报错内容
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\b.py", line 9, in
btn.comfig(state=DISABLED)
AttributeError: 'Button' object has no attribute 'comfig'
我的解答思路和尝试过的方法
试过d1['state']=DISABLED
我想要达到的结果
点击录取后按钮不可点击