我正在Kivy(Python)中编写一个绘画应用程序,我自己定位于Kivy Paint Tutorial。但是当我想添加一个Scroll funktion时(所以你可以将你的绘画的东西移到顶部,左边,右边......)我遇到了一个问题。 我添加了一个Scatter,因此绘制的所有内容都在散点图中,并且可以将它们全部移动到一起。 现在我试图添加一个菜单,但不能按下按钮,因为它被散点图所覆盖。我试图将两者放在Float布局中,但它没有用。 我的代码:
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()
和kv文件:
<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