为什么我的图片在工具栏上而不是在 kivy 的下方?
Why my image is on the toolbar not below it in kivy?
我想不通为什么我的图片在工具栏上而不是在它下面。
我尝试了很多尝试,比如改变高度等等,但它对我没有用。
任何人都可以帮助我获得正确的代码吗?
我的一段代码:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.core.window import Window
Window.size = (360 , 640)
kv = '''
#:import get_color_from_hex kivy.utils.get_color_from_hex
ScreenManager:
Second:
<Second>:
name: 'second'
MDToolbar:
id :toolbar
title: "..."
elevation: 10
specific_text_color: get_color_from_hex('#FCF6F5FF')
pos_hint: {'top':1.0}
md_bg_color: get_color_from_hex('#822057FF')
ScrollView:
MDBoxLayout:
size_hint: 1,None
adaptive_height: True
height: root.height-toolbar.height
orientation:'vertical'
AsyncImage:
source: 'national.jpg'
MDLabel:
halign:'center'
md_bg_color:get_color_from_hex('#FCF6F5FF')
text: 'National Digital Library of India (NDLI) is a virtual repository of learning resources which is not just a repository with search/browse facilities but provides a host of services for the learner community. It is sponsored and mentored by Ministry of Education, Government of India, through its National Mission on Education through Information and Communication Technology (NMEICT). Filtered and federated searching is employed to facilitate focused searching so that learners can find the right resource with least effort and in minimum time. NDLI provides user group-specific services such as Examination Preparatory for School and College students and job aspirants. '
'''
class Second(Screen):
pass
class Test(MDApp):
def build(self):
self.root = Builder.load_string(kv)
Test().run()
感谢帮助!!
ScrollView 需要使用 root.height - toolbar.height 计算高度才能正确显示。我还在第二屏下添加了Screen:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.core.window import Window
Window.size = (360 , 640)
kv = '''
#:import get_color_from_hex kivy.utils.get_color_from_hex
ScreenManager:
Second:
<Second>:
name: 'second'
Screen:
orientation: 'vertical'
MDToolbar:
id :toolbar
title: "..."
elevation: 10
specific_text_color: get_color_from_hex('#FCF6F5FF')
pos_hint: {'top':1.0}
md_bg_color: get_color_from_hex('#822057FF')
ScrollView:
size_hint_y: None
height: root.height - toolbar.height
MDBoxLayout:
size_hint: 1,None
adaptive_height: True
height: root.height-toolbar.height
orientation:'vertical'
AsyncImage:
source: 'national.jpg'
MDLabel:
halign:'center'
md_bg_color:get_color_from_hex('#FCF6F5FF')
text: 'National Digital Library of India (NDLI) is a virtual repository of learning resources which is not just a repository with search/browse facilities but provides a host of services for the learner community. It is sponsored and mentored by Ministry of Education, Government of India, through its National Mission on Education through Information and Communication Technology (NMEICT). Filtered and federated searching is employed to facilitate focused searching so that learners can find the right resource with least effort and in minimum time. NDLI provides user group-specific services such as Examination Preparatory for School and College students and job aspirants. '
'''
class Second(Screen):
pass
class Test(MDApp):
def build(self):
self.root = Builder.load_string(kv)
Test().run()
最终使用Layouts
找到解决方案,如下面的代码所示:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.core.window import Window
Window.size = (360, 640)
kv = '''
#:import get_color_from_hex kivy.utils.get_color_from_hex
ScreenManager:
Second:
<Second>:
name: 'second'
MDBoxLayout:
orientation:'vertical'
MDToolbar:
id :toolbar
title: "..."
elevation: 10
specific_text_color: get_color_from_hex('#FCF6F5FF')
pos_hint: {'top':1.0}
md_bg_color: get_color_from_hex('#822057FF')
ScrollView:
MDBoxLayout:
size_hint: 1,None
adaptive_height: True
height: 500
orientation:'vertical'
AsyncImage:
source: 'national.jpg'
MDLabel:
halign:'center'
md_bg_color:get_color_from_hex('#FCF6F5FF')
text: 'National Digital Library of India (NDLI) is a virtual repository of learning resources which is not just a repository with search/browse facilities but provides a host of services for the learner community. It is sponsored and mentored by Ministry of Education, Government of India, through its National Mission on Education through Information and Communication Technology (NMEICT). Filtered and federated searching is employed to facilitate focused searching so that learners can find the right resource with least effort and in minimum time. NDLI provides user group-specific services such as Examination Preparatory for School and College students and job aspirants. '
'''
class Second(Screen):
pass
class Test(MDApp):
def build(self):
self.root = Builder.load_string(kv)
Test().run()
我想不通为什么我的图片在工具栏上而不是在它下面。 我尝试了很多尝试,比如改变高度等等,但它对我没有用。 任何人都可以帮助我获得正确的代码吗? 我的一段代码:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.core.window import Window
Window.size = (360 , 640)
kv = '''
#:import get_color_from_hex kivy.utils.get_color_from_hex
ScreenManager:
Second:
<Second>:
name: 'second'
MDToolbar:
id :toolbar
title: "..."
elevation: 10
specific_text_color: get_color_from_hex('#FCF6F5FF')
pos_hint: {'top':1.0}
md_bg_color: get_color_from_hex('#822057FF')
ScrollView:
MDBoxLayout:
size_hint: 1,None
adaptive_height: True
height: root.height-toolbar.height
orientation:'vertical'
AsyncImage:
source: 'national.jpg'
MDLabel:
halign:'center'
md_bg_color:get_color_from_hex('#FCF6F5FF')
text: 'National Digital Library of India (NDLI) is a virtual repository of learning resources which is not just a repository with search/browse facilities but provides a host of services for the learner community. It is sponsored and mentored by Ministry of Education, Government of India, through its National Mission on Education through Information and Communication Technology (NMEICT). Filtered and federated searching is employed to facilitate focused searching so that learners can find the right resource with least effort and in minimum time. NDLI provides user group-specific services such as Examination Preparatory for School and College students and job aspirants. '
'''
class Second(Screen):
pass
class Test(MDApp):
def build(self):
self.root = Builder.load_string(kv)
Test().run()
感谢帮助!!
ScrollView 需要使用 root.height - toolbar.height 计算高度才能正确显示。我还在第二屏下添加了Screen:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.core.window import Window
Window.size = (360 , 640)
kv = '''
#:import get_color_from_hex kivy.utils.get_color_from_hex
ScreenManager:
Second:
<Second>:
name: 'second'
Screen:
orientation: 'vertical'
MDToolbar:
id :toolbar
title: "..."
elevation: 10
specific_text_color: get_color_from_hex('#FCF6F5FF')
pos_hint: {'top':1.0}
md_bg_color: get_color_from_hex('#822057FF')
ScrollView:
size_hint_y: None
height: root.height - toolbar.height
MDBoxLayout:
size_hint: 1,None
adaptive_height: True
height: root.height-toolbar.height
orientation:'vertical'
AsyncImage:
source: 'national.jpg'
MDLabel:
halign:'center'
md_bg_color:get_color_from_hex('#FCF6F5FF')
text: 'National Digital Library of India (NDLI) is a virtual repository of learning resources which is not just a repository with search/browse facilities but provides a host of services for the learner community. It is sponsored and mentored by Ministry of Education, Government of India, through its National Mission on Education through Information and Communication Technology (NMEICT). Filtered and federated searching is employed to facilitate focused searching so that learners can find the right resource with least effort and in minimum time. NDLI provides user group-specific services such as Examination Preparatory for School and College students and job aspirants. '
'''
class Second(Screen):
pass
class Test(MDApp):
def build(self):
self.root = Builder.load_string(kv)
Test().run()
最终使用Layouts
找到解决方案,如下面的代码所示:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.core.window import Window
Window.size = (360, 640)
kv = '''
#:import get_color_from_hex kivy.utils.get_color_from_hex
ScreenManager:
Second:
<Second>:
name: 'second'
MDBoxLayout:
orientation:'vertical'
MDToolbar:
id :toolbar
title: "..."
elevation: 10
specific_text_color: get_color_from_hex('#FCF6F5FF')
pos_hint: {'top':1.0}
md_bg_color: get_color_from_hex('#822057FF')
ScrollView:
MDBoxLayout:
size_hint: 1,None
adaptive_height: True
height: 500
orientation:'vertical'
AsyncImage:
source: 'national.jpg'
MDLabel:
halign:'center'
md_bg_color:get_color_from_hex('#FCF6F5FF')
text: 'National Digital Library of India (NDLI) is a virtual repository of learning resources which is not just a repository with search/browse facilities but provides a host of services for the learner community. It is sponsored and mentored by Ministry of Education, Government of India, through its National Mission on Education through Information and Communication Technology (NMEICT). Filtered and federated searching is employed to facilitate focused searching so that learners can find the right resource with least effort and in minimum time. NDLI provides user group-specific services such as Examination Preparatory for School and College students and job aspirants. '
'''
class Second(Screen):
pass
class Test(MDApp):
def build(self):
self.root = Builder.load_string(kv)
Test().run()