源码如下:

import time
from Tkinter import *
def run(): while True: txt.insert(END,'...') print '...' time.sleep(10)
root = Tk()
txt = Text(root)
txt.pack()
Button(root,text='Run',command = run).pack()
root.mainloop()

我想达到的目的:
在这个txt中没10s输出 "...".
但python中一定要等到这个 函数运行完成以后才会在txt中输入,类似这种循环就不会停下来..
而在python提供的 shell里面 print又可以实时的打印..

思路是对的,只不过你没调用更新函数,见下面标注。

# -*- coding: gb2312 -*-
import time
from Tkinter import *
def run(): while True: txt.insert(END,'...') txt.update()#我指的是加这句代码。 #下面两句,回复显示后对不齐,请注意,与上面两句平行
print '...'#这句没什么用,输出到控制台了,和Tk没关系
time.sleep(10)
root = Tk()
txt = Text(root)
txt.pack()
Button(root,text='Run',command = run).pack()
root.mainloop()

  

另外,介意用类封装一下更好管理。
代码见下:
# -*- coding: gb2312 -*-
import time
from Tkinter import * class Display:
def __init__(self):
self.root = Tk()
self.text = Text(self.root)
self.text.pack()
self.butt = Button(self.root,text='Run',command = self.run)
self.butt.pack()
def run(self):
while True:
self.text.insert(END, '...')
self.root.update()#更新以后才能看到变化
time.sleep(1)#这里为了快点看到效果,改为了1S输出一次 if __name__ == '__main__':
D = Display()
mainloop()

  

以上代码均已在python2.5下运行。

关于python Tk中实时的输出.的更多相关文章

  1. 【转】Python 字典中的中文输出问题

    import json dict = {'Title': '这是标题'} print json.dumps(dict, ensure_ascii=False, encoding='UTF-8') #结 ...

  2. python 中简单的输出语句

    1 python 中简单的输出语句 #coding:utf-8#输出的是整数,得到的也是整数,用raw_inputusername=raw_input('请输入用户名:')#输出的是整数或者字符串,得 ...

  3. python 全栈开发,Day38(在python程序中的进程操作,multiprocess.Process模块)

    昨日内容回顾 操作系统纸带打孔计算机批处理 —— 磁带 联机 脱机多道操作系统 —— 极大的提高了CPU的利用率 在计算机中 可以有超过一个进程 进程遇到IO的时候 切换给另外的进程使用CPU 数据隔 ...

  4. python语言中的编码问题(续)

    上文提到了python开发中非常重要的两处设置. 一个是编解码器的默认设置defaultencoding >>> import sys >>> sys.getdef ...

  5. Python类中super()和__init__()的关系

    Python类中super()和__init__()的关系 1.单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(sel ...

  6. 在Python应用中使用MongoDB

    Python是开发社区中用于许多不同类型应用的强大编程语言.很多人都知道它是可以处理几乎任何任务的灵活语言.因此,在Python应用中需要一个什么样的与语言本身一样灵活的数据库呢?那就是NoSQL,比 ...

  7. python虚拟机中的异常流控制

    异常:对程序运行中的非正常情况进行抽象.并且提供相应的语法结构和语义元素,使得程序员能够通过这些语法结构和语义元素来方便地描述异常发生时的行为. 1.Python中的异常机制: 1.1Python虚拟 ...

  8. 【转载】Python编程中常用的12种基础知识总结

    Python编程中常用的12种基础知识总结:正则表达式替换,遍历目录方法,列表按列排序.去重,字典排序,字典.列表.字符串互转,时间对象操作,命令行参数解析(getopt),print 格式化输出,进 ...

  9. Python编程中常用的12种基础知识总结

    原地址:http://blog.jobbole.com/48541/ Python编程中常用的12种基础知识总结:正则表达式替换,遍历目录方法,列表按列排序.去重,字典排序,字典.列表.字符串互转,时 ...

随机推荐

  1. WeakhashMap源码2

    public class WeakHashMapIteratorTest { @SuppressWarnings({ "rawtypes", "unchecked&quo ...

  2. 【转帖】H5 手机 App 开发入门:概念篇

    H5 手机 App 开发入门:概念篇 http://www.ruanyifeng.com/blog/2019/12/hybrid-app-concepts.html 作者: 阮一峰 日期: 2019年 ...

  3. [转帖]String、StringBuilder与StringBuffer

    String.StringBuilder与StringBuffer https://www.jianshu.com/p/37f3799bdb56 1.String String本质 String是不可 ...

  4. [转帖]PostgreSQL 参数调整(性能优化)

    PostgreSQL 参数调整(性能优化) https://www.cnblogs.com/VicLiu/p/11854730.html 知道一个 shared_pool 文章写的挺好的 还没仔细看 ...

  5. 用FTPClient,执行到ftp.storeFile(fileName, inputFile);无反应了

    Q:用FTPClient,执行到ftp.storeFile(fileName,  inputFile):无反应了 A:  ftpclient.enterLocalPassiveMode(); ftp. ...

  6. 7. Scala面向对象编程(中级部分)

    7.1 包 7.1.1 看一个应用场景 现在有两个程序员共同开发一个项目,程序员xiaoming希望定义一个类取名Dog,程序员xiaohong也想定一个类也叫Dog,两个程序员还为此吵了起来,该怎么 ...

  7. tornado利用装饰器记录每个http请求

    python利用装饰器记录每个http请求 设置装饰器 from functools import wraps from datetime import datetime ""&q ...

  8. tomcat启动完成执行 某个方法 定时任务(Spring)

    第一步引入接口: ServletContextListener @RestController @RequestMapping("/schedule") public class ...

  9. CLR学习之初识CLR

    一.什么是CLR? CLR即公共语言运行时(Common Language Runtime,简称CRL),就是微软为.net产品构建的运行环境,与java的JVM类似,通俗的讲就是.net虚拟机.CL ...

  10. c#十进制转换

    1.方法定义 /// <summary> /// 十进制转换 /// </summary> /// <param name="hexChar"> ...