Sugar Code Snippets: Difference between revisions

From OLPC
Jump to navigation Jump to search
m (categorization)
m (added Sugar category)
Line 33: Line 33:


[[Category:HowTo]]
[[Category:HowTo]]
[[Category:Sugar]]

Revision as of 23:09, 7 February 2007

Toolbar

This snippet shows how an activity would have a toolbar with two buttons:

import hippo

from sugar.activity.Activity import Activity
from sugar.graphics.toolbar import Toolbar
from sugar.graphics.button import Button

class FooActivity(Activity):
    def __init__(self):
        Activity.__init__(self)

        canvas = hippo.Canvas()
        self.add(canvas)
        canvas.show()
       
        vbox = hippo.CanvasBox()
        canvas.set_root(vbox)

        toolbar = Toolbar()
        vbox.append(toolbar)

        button1 = Button('button1_icon')
        button1.connect("activated", self._button1_activated_cb)
        self.append(button1)

        button2 = Button('button2_icon')
        button2.connect("activated", self._button2_activated_cb)
        self.append(button2)