【发布时间】:2020-10-12 10:19:16
【问题描述】:
我有这个文本框:
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
【问题讨论】:
标签: python tkinter console textbox stdout