Python的after方法老报错怎么办?
代码如下:importtkinterimportoswin=tkinter.Tk()win.title("照片导出2.0")L1=tkinter.Label(text="...
代码如下:
import tkinter
import os
win=tkinter.Tk()
win.title("照片导出2.0")
L1=tkinter.Label(text="照片在:").grid(row=0,column=0)
def fz():
shutil.move("f:\DCIM","C:\\Users\Administrator\Desktop\新片")
os.makedirs("f:\DCIM")
B1=tkinter.Button(text="导出",command=fz).grid(row=1,column=0)
L2=tkinter.Label(text="进度(单位:%)").grid(row=0,column=3)
class pdzp:
s=None
def pd(self):
s1=os.path.exists("f:\DCIM")
if s1 is True:
pdzp.s=os.listdir("f:\DCIM")
elif s1 is False:
pdzp.s="无"
def ds(self):
c=0
while 1:
pdzp1 = pdzp()
pdzp1.pd()
L3.after(500, pdzp1.ds)
pdzp1=pdzp()
pdzp1.pd()
L3=tkinter.Label(text=pdzp1.s).grid(row=0,column=2)
L3.after(500,pdzp1.ds)
win.mainloop()
报错代码如下:
"D:\ 他人即地狱\venv\Scripts\python.exe" "D:/ 他人即地狱/venv/8.3.py"
Traceback (most recent call last):
File "D:/ 他人即地狱/venv/8.3.py", line 28, in <module>
L3.after(500,pdzp1.ds)
AttributeError: 'NoneType' object has no attribute 'after'
Process finished with exit code 1 展开
import tkinter
import os
win=tkinter.Tk()
win.title("照片导出2.0")
L1=tkinter.Label(text="照片在:").grid(row=0,column=0)
def fz():
shutil.move("f:\DCIM","C:\\Users\Administrator\Desktop\新片")
os.makedirs("f:\DCIM")
B1=tkinter.Button(text="导出",command=fz).grid(row=1,column=0)
L2=tkinter.Label(text="进度(单位:%)").grid(row=0,column=3)
class pdzp:
s=None
def pd(self):
s1=os.path.exists("f:\DCIM")
if s1 is True:
pdzp.s=os.listdir("f:\DCIM")
elif s1 is False:
pdzp.s="无"
def ds(self):
c=0
while 1:
pdzp1 = pdzp()
pdzp1.pd()
L3.after(500, pdzp1.ds)
pdzp1=pdzp()
pdzp1.pd()
L3=tkinter.Label(text=pdzp1.s).grid(row=0,column=2)
L3.after(500,pdzp1.ds)
win.mainloop()
报错代码如下:
"D:\ 他人即地狱\venv\Scripts\python.exe" "D:/ 他人即地狱/venv/8.3.py"
Traceback (most recent call last):
File "D:/ 他人即地狱/venv/8.3.py", line 28, in <module>
L3.after(500,pdzp1.ds)
AttributeError: 'NoneType' object has no attribute 'after'
Process finished with exit code 1 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询