|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
[attachimg]1445- from tkinter import*
- from tkinter.ttk import*
- import time
- ck=Tk()
- ck.title("测试")
- ck.geometry("500x300")
- e=Text(ck)
- e.pack()
- a=5
- c=[]
- b=[0,1,2,3,4,5,6,7,8,9]
- for i in c:
- c.append(i)
- def q():
- time.sleep(3)
- e.delete(0.0,END)
- for i in b:
- e.insert(END,i)
- e.insert(END,'\n')
- while a>0:
- b.pop()
- q()
- time.sleep(3)
- a=a-1
- print(b)
- ck.mainloop()
复制代码 85[/attachimg]
二
我想让文本框隔3秒后输出新的b列表。使用print函数能隔3秒后输出新的b列表,但是文本框界面是在print函数输出[0, 1, 2, 3, 4]后才出现,而且文本框只有最后的b列表[0, 1, 2, 3, 4]。请问该怎么改代码才能达到想要的效果?
直接给条鱼你吧,
- from tkinter import *
- win = Tk()
- def update(ls):
- print(ls)
- txt.delete("1.0", END)
- txt.insert(END, ','.join(map(str, ls))+'\n')
- cancel_id = txt.after(1000, update, ls)
- if len(ls)>5:
- ls.pop()
- else:
- txt.after_cancel(cancel_id)
-
- txt = Text(win)
- txt.insert(END, "Hello\n")
- txt.pack()
- ls = list(range(9))
- win.after(1000, update, ls)
- win.mainloop()
复制代码
|
-
一
|