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()
答案 0 :(得分:0)
如果您将floatlayout
更改为boxlayout
则可行。
flt = BoxLayout(orientation='vertical')