how would I fill the entire rectangle with my image so it fits the whole screen as background?
from random import random
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.graphics import Color, Line, Rectangle
from kivy.uix.filechooser import FileChooserListView, FileChooserIconView
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
color = (random(), random(), random())
with self.canvas:
Rectangle(source='water.png', pos=(0, 0), size=self.size)
Color(*color)
d = 30.
touch.ud['line'] = Line(points=(touch.x, touch.y))
def on_touch_move(self, touch):
touch.ud['line'].points += [touch.x, touch.y]
class MyPaintApp(App):
def build(self):
parent = Widget()
painter = MyPaintWidget()
parent.add_widget(painter)
return parent
if __name__ == '__main__':
MyPaintApp().run()
right now it just displays a small image on the bottom left corner as default. I don't know how to resize or center the image because I don't know what the coordinates for the center are and the image does not resize.
It's easy to write to .kv file.
<MyPaintWidget>
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'water.png'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With