51Testing软件测试论坛
标题:
python在GUI的Text控件中如何实时显示运行log
[打印本页]
作者:
bilibili鹅
时间:
2019-11-27 14:30
标题:
python在GUI的Text控件中如何实时显示运行log
本帖最后由 bilibili鹅 于 2019-11-27 14:31 编辑
1.新建一个gui窗口
from tkinter import *
root = Tk()
text = Text(root,width=200,height=150)
text.pack()
root.mainloop()
复制代码
2.测试函数
import logging
from time import sleep
def test():
for i in range(50):
logging.info('test log %d'%i)
sleep(1)
pr = logging.StreamHandler()
logging.basicConfig(level=logging.INFO, handlers=[pr, ],
format="%(asctime)s,%(name)s,%(levelname)s : %(message)s"
)
if __name__ == '__main__':
test()
复制代码
3.求大佬指导如何运行GUI时,logging中打印一条日志,Text控件中就显示一条
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2