#!/usr/bin/env pythonimport screenletsclass HelloWorldScreenlet(screenlets.Screenlet):__name__ = 'HelloWorld'__version__ = '0.1'__author__ = 'John Doe'__desc__ = 'Simple Hello World Screenlet'def __init__(self, **kwargs):# Customize the width and height.screenlets.Screenlet.__init__(self, width=180, height=50, **kwargs)def on_draw(self, ctx):# Change the color to white and fill the screenlet.ctx.set_source_rgb(255, 255, 255)self.draw_rectangle(ctx, 0, 0, self.width, self.height)# Change the color to black and write the message.ctx.set_source_rgb(0, 0, 0)text = 'Hello World!'self.draw_text(ctx, text, 10, 10, "Sans 9" , 20, self.width)if __name__ == "__main__":import screenlets.sessionscreenlets.session.create_session(HelloWorldScreenlet) 每一個應用程序都必須導入 screenlet 框架并創建新的會話,還有一些其他的最低要求,包括任何初始化步驟以及基本繪圖函數,以便在屏幕上呈現小部件,TestScreenlet.py 示例具有用來初始化對象的 __init__方法。在本例中,您將看到一行,包含對 screenlet 的 __init__方法的調用,它設置要為此應用程序創建的窗口的初始寬度和高度。