File: Tutorial_12_text_view.py

package info (click to toggle)
sugar-pippy-activity 76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,664 kB
  • sloc: python: 5,860; makefile: 16; sh: 1
file content (42 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class PyApp(Gtk.Window):

    def __init__(self):
        super(PyApp, self).__init__()

        self.set_title('Text view')
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_size_request(250, 150)

        scrolled = Gtk.ScrolledWindow()

        textview = Gtk.TextView()
        scrolled.add(textview)

        textbuffer = textview.get_buffer()
        textbuffer.set_text('Multiple lines\nin the same editor\n')

        end = textbuffer.get_end_iter()
        anchor = textbuffer.create_child_anchor(end)
        box = Gtk.HBox()
        textview.add_child_at_anchor(box, anchor)

        button = Gtk.Button(label='Click me')
        button.connect('clicked', self._clicked_cb, textbuffer)
        box.pack_start(button, False, False, 0)

        self.add(scrolled)
        self.show_all()

        self.connect('destroy', Gtk.main_quit)

    def _clicked_cb(self, button, textbuffer):
        end = textbuffer.get_end_iter()
        textbuffer.insert(end, 'You clicked the button!!\n')


PyApp()
Gtk.main()