如何解决文本窗口小部件中的Tkinter window_create与其他GUI重叠
我正在使用Python 3.8和Tkinter进行聊天。 我已经通过Text小部件的window.create()方法实现了彩色文本。 但是,当您开始向上滚动时,此文本将与程序界面的其余部分重叠。我怎样才能解决这个问题?
这是我正在使用的代码:
def coloredOutput(self,bg,fg,text):
try:
a = []
for line in text.split('\n'):
a.append(len(line))
if len(a) <= 10:
label = Text(bg=bg,fg=fg,width=max(a),height=len(a),borderwidth=0)
label.insert(1.0,text)
label.configure(state=disABLED)
else:
msg = "~ too many lines! 10 is max,but there's " + str(len(a)) + " lines in this message ~"
label = Text(bg="red",fg="white",width=len(msg),height=1,msg)
label.configure(state=disABLED)
except Exception as e:
print(e)
msg = "Formatting error! Maybe your message is not properly formatted?"
label = Text(bg="red",borderwidth=0)
label.insert(1.0,msg)
label.configure(state=disABLED)
self.text.window_create(END,window=label)
感谢您的帮助。对不起,我的英语有误,我来自乌克兰。
解决方法
用window_create
添加的窗口必须是文本窗口小部件的子级,而不是根窗口的子级。
label = Text(self.text,...)
self.text.window_create(END,label)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。