我有这个文本框:
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)
并在代码末尾使用此命令激活stdout以使用redirector()进行写入
但有时,当我点击我的控制台,并上下滚动时,它会在中间部分打印,而不是在文本框的末尾打印。
有没有一个解决办法,使新的印刷品总是被强迫打破盒底
sys.stdout.write=redirector
这是因为您正在
INSERT
位置之后插入文本。这里,INSERT
表示光标的位置。如果要在文本小部件的末尾插入文本,则需要将INSERT
替换为END
相关问题 更多 >
编程相关推荐