Scatter Covers whole display kivy

孤街醉人 提交于 2020-01-02 18:04:31

问题


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

来源:https://stackoverflow.com/questions/43925919/scatter-covers-whole-display-kivy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!