赞
踩
想实现效果:
点下按钮后,调用函数,不可再点击按钮,函数调用结束,按钮才可再次点击。
尝试:
import tkinter import time def bc(): b1['state'] = 'disable' for i in range(4, 0, -1): tkinter.Label(root, text=f'倒计时{i}秒 ').place(x=50, y=120) time.sleep(1) b1['state'] = 'normal' root = tkinter.Tk() root.geometry('200x200') b1 = tkinter.Button(root, text='按钮', bd=3, command=bc) b1.place(x=50, y=50) root.mainloop()
结果:
修改:
import threading import tkinter import time def thread_it(fc): t = threading.Thread(target=fc) t.setDaemon(True) t.start() def bc(): b1['state'] = 'disable' for i in range(10, 0, -1): tkinter.Label(root, text=f'倒计时{i}秒 ').place(x=50, y=120) time.sleep(1) b1['state'] = 'normal' root = tkinter.Tk() root.geometry('200x200') b1 = tkinter.Button(root, text='按钮', bd=3, command=lambda: thread_it(bc)) b1.place(x=50, y=50) root.mainloop()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。