我有这个文本框:
t_outputbox = tk.Text(tab_console, width=99, height=18, font='Tahoma 12',bg='#051da3', fg='#d9d9d9', relief="flat", highlightthickness=1, borderwidth=1)
并使用一个函数将所有控制台输出打印到它:
def redirector(inputStr): # send all prints to GUI instead of console
t_outputbox.config(state=NORMAL)
t_outputbox.insert(INSERT, inputStr)
t_outputbox.see(END)
t_outputbox.config(state=DISABLED)
并在我的代码的 ned 处使用这个命令来激活 stdout 以使用 redirector() 来编写。
但是有时,当我单击控制台并上下滚动时,它确实会打印在中间的某个地方而不是文本框的末尾。
有没有办法解决这个问题,以便新的印刷品总是能打败盒子的末端?
sys.stdout.write=redirector