简体   繁体   English

在ScrolledWindow中滚动TextView,以便在pyGTK2中可见光标

[英]scroll TextView in ScrolledWindow so that cursor is visible in pyGTK2

I have a Textview in a ScrolledWindow. 我在ScrolledWindow中有一个Textview。 I have set up a callback on signal "changed" of textbuffer of the textview. 我已经在textview的textbuffer的信号“ changed”上设置了一个回调。 Now I need to scroll the ScrolledWindow to the point of the cursor. 现在,我需要将ScrolledWindow滚动到光标的位置。 How do I do that? 我怎么做?

self.outgoing = gtk.ScrolledWindow()
self.outgoing.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.textview = gtk.TextView()
textbuffer=self.textview.get_buffer()
textbuffer.connect("changed",self.scrolltocursor)
self.outgoing.add_with_viewport(self.textview)

def scrolltocursor(self,text_buffer):
    <I don't know what to do here>

Help please. 请帮助。

Well it seems the problem was that I did add_with_viewport to put the textview in the scrolled window. 好吧,看来问题是我做了add_with_viewport来将textview放在滚动窗口中。 Now I tried self.outgoing.add(self.textview) and it works without any callbacks to change. 现在,我尝试了self.outgoing.add(self.textview) ,它可以正常工作而无需更改任何回调。 So yeah. 是的。 That fixes it. 那就解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM