Scatter Covers whole display kivy

2019-06-05 04:14发布

问题:

im writing a paint app in Kivy (Python) and i orientated myself at the Kivy Paint Tutorial. But when I wanted to add a Scroll funktion (so you can move your painted things to the top, left, right...) i came to an problem. I added a Scatter, so everything that is drawn is inside the scatter and it is posible to move it all together. Now im trying to add a menu but it isnt possible to press the button, because it is covered by the scatter. I tried to put both in a Float layout, but it didnt worked. My code:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty, NumericProperty, 
ReferenceListProperty, StringProperty, ListProperty, BooleanProperty
from kivy.uix.popup import Popup
from kivy.graphics import Color, Line
from kivy.uix.widget import Widget


class Game(Screen):
scroll = BooleanProperty(False)
colorx = (1,1,1)

def on_touch_down(self, touch):
    if touch.is_double_tap:
        if self.scroll:
            self.scroll = False
        else:
            self.scroll = True

    with self.layout.canvas:
        Color(self.colorx)
        touch.ud['line'] = Line(points=(touch.x - self.layout.x, touch.y - self.layout.y))



def on_touch_move(self, touch):
    if self.scroll:
        self.layout.x += (touch.dx)
        self.layout.y += (touch.dy)
    else:
        touch.ud['line'].points += [(touch.x - self.layout.x), (touch.y - self.layout.y)]



class Manager(ScreenManager):

screen_one = ObjectProperty(None)

class ScreensApp(App):

def build(self):
    return Manager()

ScreensApp().run()

and the kv file:

<Game>:
layout: layout
FloatLayout:
    Button:
        pos_hint: {"x": 0.1, "y":0.2}
        size_hint: 0.1, 0.1
    Scatter:
        id: layout



<Manager>:
id: screen_manager

screen_one: screen_one


Game:
    id: screen_one
    name: "game"
    manager: screen_manager