Kivy - Two sliders in a layout

时间:2017-08-04 12:54:23

标签: python slider kivy

I am trying to use two sliders in layout. The code is given below. The problem is only the second slider responds to the mouse actions. The first slider (and also the button) does not respond at all to the mouse actions. How to make both sliders responsive? Thanks in advance

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.slider import Slider
from kivy.uix.button import Button

def Exit(instance):
    print('Exit the screen')
    App.get_running_app().stop()

def MainScreen():
    flt = FloatLayout()

    button = Button(text='Hello Kivy World')
    button.size = (200, 100)
    button.size_hint = (None, None)
    button.pos_hint = {'center_x': .5, 'center_y': .2}
    button.bind(on_press=Exit)
    flt.add_widget(button)

    slid1 = Slider()
    slid1.id = 'Slider 01'
    slid1.size_hint_x = .75
    slid1.pos_hint = {'x': .125, 'center_y': .5}
    slid1.value_track = True
    slid1.value_track_color = [0, 1, 0, 1]
    slid1.sensitivity = 'handle'
    flt.add_widget(slid1)

    slid2 = Slider()
    slid2.id = 'Slider 02'
    slid2.size_hint_x = .75
    slid2.pos_hint = {'x': .125, 'center_y': .75}
    slid2.value_track = True
    slid2.value_track_color = [1, 0, 0, 1]
    slid2.sensitivity = 'handle'
    flt.add_widget(slid2)

    return flt

class MainApp(App):

    def build(self):
        return MainScreen()

if __name__ == "__main__":
    app = MainApp()
    app.run()

1 个答案:

答案 0 :(得分:0)

如果您将floatlayout更改为boxlayout则可行。

flt = BoxLayout(orientation='vertical')