Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 刷新空闲输出_Python_Python Idle - Fatal编程技术网

Python 刷新空闲输出

Python 刷新空闲输出,python,python-idle,Python,Python Idle,我有一个python脚本,它使用以下代码每秒更新一个变量: import threading m = 0 def printthis(): threading.Timer(0.5,printthis).start() def f1(): global m m = m + 1 return f1() printthis() 我希望每秒钟在空闲shell上更新变量m。我不希望程序只打印1,2,3,4。。。我希望它打印1,然后刷

我有一个python脚本,它使用以下代码每秒更新一个变量:

import threading
m = 0
def printthis():
    threading.Timer(0.5,printthis).start()
    def f1():
        global m
        m = m + 1
        return
    f1()
printthis()

我希望每秒钟在空闲shell上更新变量m。我不希望程序只打印1,2,3,4。。。我希望它打印1,然后刷新shell以显示变量已更改为什么。

如果您希望控制输出屏幕,无论程序如何运行,请创建一个可以控制的屏幕。下面的tkinter程序按照您的要求执行,包括在空闲状态下运行,这是我快速开发它的地方

import tkinter as tk

root = tk.Tk()
text = tk.Text(root)
text.pack()

m = 0
def update():
    global m
    text.delete('1.0', 'end')
    text.insert('1.0', str(m))
    m += 1
    root.after(1000, update)
update()  # initialize cycle

root.mainloop()

这不会在空闲时工作,它不是一个真正的tty。闲散是必要的吗?应该有帮助。Idle是一种开发环境,通常不用于已开发程序的常规运行。一个例外是在Windows上,unicode支持优于命令提示符。2.Python不定义控件字符的效果,包括写入“文件”(包括stdout和stderr)时的\r效果。在通用换行符模式下,Python本身将\r解释为\n。将1和2放在一起,您应该在控制台窗口中使用\r直接与
python
结合使用的程序,该窗口解释为“返回到行的开头”。非常感谢!我必须学习tkinter——我仍然是一个python迷。