Sugar Code Snippets: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Added toolbar example.) |
||
Line 1: | Line 1: | ||
= Toolbar = |
= 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) |
Revision as of 19:01, 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)