设置从一点到另一点的笔划

2024-03-28 21:40:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要知道如何使一个笔划被自动删除,如果它不是用户应该作出的笔划

例如,当用户将手指从屏幕上提起时,用户所做的任何没有从点1到点2的笔划都会自动删除。如果笔划从点1移动到点2,则应保持在屏幕上。我不知道怎么做Fix stroke from point 1 to point 2

编辑内容

我试图改变代码,但我不能做我想做的事。我已经尝试了一千种选择,但我无法解决它。我把编辑过的代码放在这里,希望有人能帮我

*.kv

#:kivy 1.9.0

<DrawGame>:
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'center'
        padding: 25
        Image:
            source: 'data/img/letra_a/a-trazo.png'

<ImageEx>:
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'center'
        padding: 25
        Image:
            source: 'data/img/letra_a/avestruz.png'
            
<SoundEx>:
    BoxLayout:
        orientation: 'horizontal'
        padding: 25
        Button:
            size_hint: 0.9, 0.3
            pos_hint: {'center_x':0.5, 'center_y':0.5}
            text: "Escuchar palabra"
            bold: True
            background_color: (.66, .38, .14, 1)
            on_release: root.play_sound()
            
<ContainerBox>:
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'data/img/fondobosque.jpg'
    orientation: 'vertical'
    Label:
        text: 'En este juego debes escribir con tu dedo, de manera correcta, la letra por la que empieza la imagen que le acompa�a. Adem�s podr�s escuchar su pronunciaci�n'
        size_hint_y: None
        text_size: self.width, None
        height: self.texture_size[1]
        halign: 'center'
        valign: 'middle'
        padding: (20,15)
        font_size: 25
        color: (.66, .38, .14, 1)
        canvas.before:
            Rectangle:
                size: self.size
                pos: self.pos
                source: 'data/img/texturacuaderno.png'
                
    BoxLayout:  
        orientation: 'horizontal'
        DrawGame:
        BoxLayout:
            orientation: 'vertical'
            BoxLayout:
                orientation: 'vertical'
                ImageEx:
                SoundEx:
        Button:
            size_hint:.06, 0.1
            text: "Volver al men�"
            on_release: app.root.current = 'menu'
            

*.py

import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.image import Image
from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty
from kivy.graphics import Ellipse, Line, Color
from kivy.vector import Vector
from kivy.clock import Clock
from random import randint
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.config import Config
from kivy.core.window import Window
from kivy.core.audio import SoundLoader


#Builder.load_file('letras.kv')

class DrawGame(BoxLayout):
    def __init__(self, **kwargs):
        super(DrawGame, self).__init__(**kwargs)
   
    def on_touch_down(self, touch):
        print(touch)
        with self.canvas:
            Color(0,1,0,0.5)
            touch.ud["line"] = Line(points=(touch.x, touch.y), width=10)
            startpoint = touch.ud["line"]
            
    def on_touch_move(self, touch):
        print(touch)
        touch.ud["line"].points += (touch.x, touch.y)
        
    def on_touch_up(self, touch, startpoint):
        print("Released!", touch)
        if startpoint.x == 393.0 and startpoint.y == 397.0:
            if touch.x == 464.0 and touch.y == 574.0:
                pass
            else:
                touch.ud["line"] = None
        else:
            touch.ud["line"] = None
        
        
class ImageEx(BoxLayout):
    def __init__(self, **kwargs):
        super(ImageEx, self).__init__(**kwargs)
        
class SoundEx(BoxLayout):
    def __init__(self, **kwargs):
        super(SoundEx, self).__init__(**kwargs)
        
    def play_sound(self):
        sound = SoundLoader.load('data/sound/letra_a/avestruz.mp4')
        if sound:
            sound.play()
        
class ContainerBox(BoxLayout):
    def __init__(self, **kwargs):
        super(ContainerBox, self).__init__(**kwargs)
            
class LetrasApp(App):
    def build(self):
        #Window.fullscreen = 'auto'
        return ContainerBox()
    
if __name__ == "__main__":
    LetrasApp().run()

La salida es el-siguiente错误:

TypeError: on_touch_up() missing 1 required positional argument: 'startpoint'