Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created September 1, 2012 18:30
Show Gist options
  • Save tshirtman/3582544 to your computer and use it in GitHub Desktop.
Save tshirtman/3582544 to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.graphics.texture import Texture
class MyWidget(Widget):
def __init__(self, **args):
super(MyWidget, self).__init__(**args)
self.texture = Texture.create(size=(2, 1), colorfmt='rgb')
color1 = 0
color2 = 255
buf = ''.join(map(chr, [color1, color2]))
self.texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
with self.canvas:
Rectangle(pos=self.pos, size=self.size, texture=self.texture)
class TestApp(App):
def build(self):
return MyWidget(size=(200, 200))
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment