我正在尝试在python gtk3中创建一个可格式化的文本框,但是在运行时,这只会出现分段错误。有没有人知道如何通过line.char索引创建和配置文本框标记?
Class window(gtk.Window):
def __init__(self):
super().__init__()
self.frame = gtk.VBox()
self.add(self.frame)
self.b = gtk.Button("Highlight")
self.b.connect("clicked", lambda event: self.configure_text(0.0, 1.5, background="red"))
self.frame.pack_start(self.b, False, True, 0)
self.text = gtk.TextView()
self.frame.pack_start(self.text, False, True, 0)
self.textbuff = self.text.get_buffer()
self.tags = []
self.show_all()
def configure_text(self, index1, index2, **args):
index1_ = gtk.TextIter()
index1_.set_line(int(float(index1)))
index2_ = gtk.TextIter()
index2_.set_line(int(float(index2)))
tag = self.textbuff.create_tag("ping!", background="orange")
self.textbuff.apply_tag(tag, index1_, index2_)
self.tags.append(tag)