I have added scroll view to my kivy app but to my surprise every time I scroll vertically, the screen automatically brings me back to the initial position of the output screen. Is there any way to stop the persistent recoil I face in my app?
use input of type(any string seperated with "," and without spaces) : "what,do,i,say,about,myself,what,do,i,say,about,myself,what,do,i,say,about,myself,what,do,i,say,about,myself,what,do,i,say,about,myself,what,do,i,say,about,myself,what,do,i,say,about,myself."
My code goes like this. This is my absl.py file.
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivy.factory import Factory
Window.size = (600, 600)
class HelpWindow(Screen):
"""
This is a help window. It contains the functionality of all the given boxes
on the main window.
"""
def main_window(self):
sm.current = "main"
class MainWindow(Screen):
"""
This is the main window that contains the main form.
This connects the frontend of the app to the backend
"""
target = ObjectProperty(None)
def v_popup(self):
version_popup()
def help(self):
sm.current = "help"
def output_window(self):
sm.current = "output"
def get_results(self):
out_window = self.manager.get_screen('output')
out_window.main(self.target.text)
sm.current = "output"
class OutputWindow(Screen):
"""
This is the output window. All the generated results will be seen here.
"""
res = ObjectProperty(None)
res_out = ObjectProperty(None)
def main(self, options):
options = list(options.split(","))
for item in options:
self.res_out.add_widget(Label(size_hint_y=None,height=30,text=item))
def main_window(self):
sm.current = "main"
class WindowManager(ScreenManager):
pass
def version_popup():
"""
Version Popup Window.
"""
version = "v1.0"
version_text = "this is "+version+" for this app"
vpop = Popup(title="Version",
content=Label(text=version_text),
size_hint=(None, None), size=(400, 400))
vpop.open()
### main builder and WindowManager object
kv = Builder.load_file("start.kv")
sm = WindowManager()
### Adding screens to widget
screens = [MainWindow(name="main"), HelpWindow(name="help"), OutputWindow(name="output")]
for screen in screens:
sm.add_widget(screen)
sm.current = "main"
### main working
class AnubisApp(App):
def build(self):
return sm
if __name__ == '__main__':
AnubisApp().run()
and this is my start.kv file.
<HelpWindow>
name:"help"
Button:
id:ms
text:"Main Screen"
on_release:
root.manager.transition.direction = "left"
root.main_window()
<MainWindow>
name:"main"
target : target
GridLayout:
cols:1
GridLayout:
cols:3
row_force_default: True
row_default_height: 50
Button:
id:hp
text:"Help"
on_release:
root.manager.transition.direction = "right"
root.help()
Button:
id:version
text: "Version"
on_release:
root.v_popup()
GridLayout:
cols:2
row_force_default: True
row_default_height: 30
Label:
text:"Target *"
TextInput:
id:target
multiline:False
GridLayout:
cols:3
row_force_default: True
row_default_height: 50
Label:
text:""
Button:
text:"Submit"
on_release:
root.get_results()
Label:
text:""
<OutputWindow>
name:"output"
res_out:res_out
GridLayout:
cols:1
ScrollView:
GridLayout:
id:res_out
cols : 1
size_hint_y: None
Button:
id:ms
size_hint_y : .1
text:"Main Screen"
on_release:
root.manager.transition.direction = "right"
root.main_window()
I might guess the issue can be of my system only but I am not so sure about that. Also, setting the height, width, and color of the scrollbar was not working on it. I added few lines in "ScrollView" but were not working.
ScrollView:
size_hint : None, None
height : 150
width : 20
bar_color : [.7, .7, .7, .9]
I cannot reproduce the recoil issue, but you must specify a height for the GridLayout
in order for the scrolling to work:
GridLayout:
id:res_out
cols : 1
size_hint_y: None
height: self.minimum_height # required to size GridLayout