[Python] Scroll and Scatter scale

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    My problem: In this script the do_translation is working. The do_scale does not work. The scrolling and scale interfere with each other. If I change the ‘do_scroll_y’ to False the do_scale works fine, but of course the scroll doesn’t. I have looked through all question about scrolling and Scatter, but did not find any question with the same problem. I have used AI Copilot for help and CoPilot changes the Scroll to ‘PinchScrollView’ and the Scatter widget to ‘Pinch to Zoom’, with the same results. To keep the code short I have removed those solutions. Can you help?

    from kivy.app import App
    from kivy.uix.boxlayout import BoxLayout
    from kivy.lang import Builder
    from kivy.uix.button import Button
    from kivy.uix.image import Image
    from kivy.uix.widget import Widget
    from kivy.uix.gridlayout import GridLayout
    from kivy.uix.screenmanager import ScreenManager, Screen
    from kivy.properties import ObjectProperty
    from kivy.properties import StringProperty
    #from kivy.uix.stencilview import StencilView
    from kivy.uix.scatter import Scatter
    import webbrowser
    kv_text='''
    <Image>:

    <ScatterWidget>:
    #do_rotation: False
    #do_translation_y: False
    #auto_bring_to_front: False

    <MyScreenManager>:
    HomeScreen:

    <HomeScreen>:

    ScrollView:
    do_scroll_x:False
    #do_scroll_y:False
    size: root.width, root.height
    size_hint_y:None
    height:0


    MGridLayout:
    cols:1
    rows:3
    size_hint_y:None
    height:self.minimum_height
    row_default_height:1650
    #row_force_default: False
    spacing:'10dp'
    padding: ['10dp','8dp']


    StencilView:
    id:stencil
    ScatterWidget:
    pos: stencil.pos
    size: my_image.size
    do_scale: True
    do_rotation: False
    #do_translation:False
    auto_bring_to_front: False
    AsyncImage:
    id: my_image
    size: stencil.width, stencil.height
    source:'https://sybe3.github.io/assets/ww_1.jpg'
    #fit_mode: 'contain'

    StencilView:
    id: stencil1
    ScatterWidget:
    pos: stencil1.pos
    size: my_image1.size
    do_scale: True
    do_rotation: False
    #do_translation:False
    auto_bring_to_front: False
    AsyncImage:
    id: my_image1
    size: stencil1.width, stencil1.height
    #source: 'piccolo2.jpg'
    source:'https://sybe3.github.io/assets/ww_1.jpg'
    #fit_mode:'contain'

    StencilView:
    id: stencil2
    ScatterWidget:
    pos: stencil2.pos
    size: my_image2.size
    do_scale: True
    #do_rotation: False
    #do_translation:False
    auto_bring_to_front: False
    AsyncImage:
    id: my_image2
    size: stencil2.width, stencil2.height
    #source: 'pizza.jpg'
    source:'https://sybe3.github.io/assets/ww_1.jpg'
    #fit_mode:'contain'


    '''
    class HomeScreen(Screen):
    def __init__(self,**kwargs):
    super(HomeScreen,self).__init__(**kwargs)

    class MGridLayout(GridLayout):
    pass


    class ScatterWidget(Scatter):
    source=StringProperty(None)
    def __init__(self, **kwargs):
    super().__init__(**kwargs)



    class ImageWidget(Widget):
    pass

    class MyMenuApp(App):

    def build(self):
    return HomeScreen()

    def main():
    Builder.load_string(kv_text)
    app = MyMenuApp()
    app.run()

    if __name__ == '__main__':
    main()

    Continue reading...

Compartilhe esta Página