I am trying use the code on Kivy website to learn Texture
. However, the following code on kivy website has a type problem:
texture = Texture.create(size=(64, 64))
size = 64 * 64 * 3
buf = [int(x * 255 / size) for x in range(size)]
buf = b''.join(map(chr, buf)) # This is the code with a problem
texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
with self.canvas:
Rectangle(texture=texture, pos=self.pos, size=(64, 64))
Because b''.join()
only accepts bytes-like object
not str
and chr
returns str
, I got this Error:
TypeError: sequence item 0: expected a bytes-like object, str found
I am using Python 3.7 and Kivy 1.11.1.
Am I missing something here? I copied the exact code on this page: https://kivy.org/doc/stable/api-kivy.graphics.texture.html