我已经在我的 kivy 应用程序中添加了 ScrollView ,但令我惊讶的是,每次我垂直滚动时,屏幕都会自动带我回到输出屏幕的初始位置。有什么方法可以阻止我在应用程序中遇到的持续后坐力吗?
使用类型的输入(任何用“,”分隔且不带空格的字符串):“what,do,i,say,about,myself,what,do,i,say,about,myself,what,do,i说,关于,我自己,做什么,我,说,关于,我自己,做什么,我,说,关于,我自己,做什么,我,说,关于,我自己,什么,做,我,说,关于我自己。”
我的代码是这样的。这是我的absl.py 文件。
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()
这是我的 start.kv 文件。
<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()
我可能猜测问题可能仅出在我的系统上,但我对此不太确定。此外,设置滚动条的高度、宽度和颜色也不起作用。我在“ScrollView”中添加了几行,但没有工作。
ScrollView:
size_hint : None, None
height : 150
width : 20
bar_color : [.7, .7, .7, .9]
最佳答案
我无法重现反冲问题,但您必须指定 GridLayout
的高度才能使滚动正常工作:
GridLayout:
id:res_out
cols : 1
size_hint_y: None
height: self.minimum_height # required to size GridLayout
关于kivy - ScrollView 向下滚动后弹回顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67795527/