在Tk中,可以创建一个显示相同内容的文本小部件的同位体 内容。也可以将对等方的字体设置为其他字体 比原始同级字体的字体大小。
这很有效,直到我想使文本的一部分变为粗体为止(在原始文本中 小部件,但对等文本是否也以粗体显示也没关系。据,直到...为止 通过查看text(3tk)可以看出, 除了用粗体创建标记外,没有其他方法可以粗化文本的一部分 字体。但随后也会在同级中使用该字体,包括 字体。
import tkinter
root = tkinter.Tk()
text = tkinter.Text(root)
text.pack(side='left', fill='both', expand=True)
text.insert('end', 'hello world\n' * 10)
# Problem: the font size of the tag applies in both text widgets
text.tag_config('foo', font=('Monospace', 12, 'bold'))
text.tag_add('foo', '2.2', '2.7')
peer = tkinter.Text(root)
peer.destroy() # the underlying tk widget gets replaced with the peer
text.peer_create(peer, font=('Monospace', 3, ''))
peer.pack(side='left', fill='y')
root.mainloop()
答案 0 :(得分:0)
有一个标签仅适用于对等方之一。是sel
,并且
它代表正在选择的文本。这有效:
peer.tag_config('sel', font=('Monospace', 3, ''))
peer.tag_add('sel', '1.0', 'end')
一个很大的缺点是,当 粗体部分未被选中。如果您不需要选择任何东西 否则,您可以强制始终选择所有文本。