- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 Kivy 新手,但能够创建一个单屏应用程序。一切看起来都很好,直到我需要添加更多屏幕。一页应用程序显示正确,但当我添加屏幕时,BoxLayouts 不再按我的预期工作。所有小部件都在屏幕底部呈现在彼此之上。我的问题是我在实现 ScreenManager 时做错了什么?
单屏应用程序如下所示:
我决定将其设为多屏,但是当我添加 ScreenManager 逻辑时,生成的屏幕如下所示:
我从this tutorial获取信息
我的 main.py 文件如下所示:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
class Pay_screen(Screen):
pass
class Survey_screen(Screen):
pass
class Finish_screen(Screen):
pass
class Sm(ScreenManager):
pass
class Next_root(BoxLayout):
pass
class Nq_disagree_label(Label):
pass
class Nq_question_label(Label):
pass
class Nq_button(Button):
pass
class survey_form(BoxLayout):
#dept_button = ObjectProperty()
def send_survey(self):
mypopup = MyPopup()
mypopup.show_popup('Survey', 'Survey sent!', 'OK!')
def add_comment(self):
mypopup = MyPopup()
mypopup.show_popup('Comment', 'This is where a comment is added.', 'OK!')
def close_app(self):
App.get_running_app().stop()
class MyPopup(Popup):
def show_popup(self, title_text, label_text, button_text):
mytext= label_text
content = BoxLayout(orientation="vertical")
content.add_widget(Label(text=mytext, font_size=20, text_size=(300, None)))
mybutton = Button(text="Ok!", size_hint=(1,.20), font_size=20)
content.add_widget(mybutton)
mypopup = Popup(content = content,
title = title_text,
auto_dismiss = False,
size_hint = (.5, .5)) #,
#font_size = 20)
mybutton.bind(on_press=mypopup.dismiss)
mypopup.open()
class nextqualApp(App):
icon = 'nextqual.png'
title = 'Pay / survey / join'
if __name__ == '__main__':
nextqualApp().run()
我的屏幕管理器 KV 文件如下所示:
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
Sm:
transition: FadeTransition()
Survey_screen:
Pay_screen:
<nq_button@Button>:
halign: "center"
text: "Add\ncomment"
size_hint_x: 10
<Nq_disagree_label@Label>:
halign: "left"
size_hint_x: 10
text:"Strongly\ndisagree"
<Nq_agree_label@Label>:
halign: "left"
size_hint_x: 10
text:"Strongly\nagree"
<Nq_question_label@Label>:
halign: "left"
font_size: "24"
size_hint_x: 25
<Pay_screen>:
name: 'pay'
#orientation: "vertical"
#padding: 6
#font_size: 24
BoxLayout:
height: "40dp"
Button:
text: "Pay your bill"
on_release: app.root.current = 'pay'
Button:
text: "Tell us how we did"
on_release: app.root.current = 'survey'
Button:
text: "I'm finished"
BoxLayout:
Button:
text: "Pay your bill"
on_release: app.root.current = 'survey'
<Survey_screen>:
name: "survey"
#orientation: "vertical"
#padding: 6
#font_size: "24"
BoxLayout:
height: "40dp"
Button:
text: "Pay your bill"
on_release: app.root.current = 'pay'
Button:
text: "Tell us how we did"
on_release: app.root.current = 'survey'
Button:
text: "I'm finished"
BoxLayout:
halign: "center"
Image:
source: "logo.jpg"
#size: self.size
BoxLayout:
height: "80dp"
size_hint_y: None
Label:
bold: True
#color: 10,10,10,10
#halign: "center"
#text_size: self.size
markup: True
text: "[color=f9f752]Description[/color]"
multiline: True
#size_hint_x: 25
text_size: self.size
halign: 'center'
valign: 'middle'
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The service I recieved from start to finish was excellent."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "I waited an appropriate amount of time for my food and drink."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The quality and presentation of the food was outstanding."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The prices provide good value for money."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The atmosphere was relaxing and enjoyable."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The overall cleanliness was very acceptable."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "I will recommend Synterest to my friends and family."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "100dp"
size_hint_y: None
Label:
size_hint_x: 40
Button:
size_hint_x: 20
text:"Send survey"
halign: "center"
on_press: root.send_survey()
Label:
size_hint_x: 40
没有屏幕管理器的 KV 文件如下所示:
nq_button@Button>:
halign: "center"
text: "Add\ncomment"
size_hint_x: 10
<Nq_disagree_label@Label>:
halign: "left"
size_hint_x: 10
text:"Strongly\ndisagree"
<Nq_agree_label@Label>:
halign: "left"
size_hint_x: 10
text:"Strongly\nagree"
<Nq_question_label@Label>:
halign: "left"
font_size: "24"
size_hint_x: 25
survey_form:
<survey_form>:
name: "survey"
orientation: "vertical"
padding: 6
font_size: "24"
BoxLayout:
height: "40dp"
Button:
text: "Pay your bill"
on_release: app.root.current = 'pay'
Button:
text: "Tell us how we did"
on_release: app.root.current = 'survey'
Button:
text: "I'm finished"
BoxLayout:
halign: "center"
Image:
source: "logo.jpg"
#size: self.size
BoxLayout:
height: "80dp"
size_hint_y: None
Label:
bold: True
#color: 10,10,10,10
#halign: "center"
#text_size: self.size
markup: True
text: "[color=f9f752]At Synterest, we care deeply about your impressions of our food, service and atmosphere. We would be very grateful if you took a few moments to give us your feedback on how you enjoyed your meal.[/color]"
multiline: True
#size_hint_x: 25
text_size: self.size
halign: 'center'
valign: 'middle'
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The service I recieved from start to finish was excellent."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "I waited an appropriate amount of time for my food and drink."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The quality and presentation of the food was outstanding."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The prices provide good value for money."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The atmosphere was relaxing and enjoyable."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "The overall cleanliness was very acceptable."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_question_label:
text: "I will recommend Synterest to my friends and family."
BoxLayout:
height: "40dp"
size_hint_y: None
Nq_disagree_label:
Slider:
size_hint_x: 80
value: 50
Nq_agree_label:
nq_button:
on_press: root.add_comment()
BoxLayout:
height: "100dp"
size_hint_y: None
Label:
size_hint_x: 40
Button:
size_hint_x: 20
text:"Send survey"
halign: "center"
on_press: root.send_survey()
Label:
size_hint_x: 40
最佳答案
经过长时间的思考,有时答案就会变得显而易见。
Survey_screen 和 Pay_screen 继承自 Main.py 文件中的 Screen。当我制作最初的一页应用程序时,根小部件继承自 BoxLayout。
我向 .kv 文件中的每个屏幕添加了一个 BoxLayout,并将所有内容放在正确的位置。
例如,
<Survey_screen>:
name: "survey"
BoxLayout:
orientation: "vertical"
padding: 6
BoxLayout:
height: "40dp"
size_hint_y: None
Button:
等等
关于python - Kivy ScreenManager 破坏了 BoxLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52644626/
我正在尝试创建启动画面。 这是代码。 from kivy.app import App from kivy.uix.image import Image from kivy.uix.screenman
我想在我的游戏中创建一个由 Kivy 编码的菜单,玩家可以在其中选择不同的选项并启动游戏。 我已经了解了 ScreenManager 模块,但我不知道它是否适合于此: from kivy.uix.sc
我正在尝试使用 get_screen() 函数来获取一个屏幕,该屏幕的名称以字符串形式给出。但令人烦恼的是,我不断收到 TypeError: 'kivy.properties.ListPropert
我正在尝试更新另一个屏幕中存在的字段,但没有成功。当有人能告诉我我在这里做错了什么时,我会非常非常高兴。 myscreenskv.py: style = r''' # File: myscreensk
我是 Kivy 新手,但能够创建一个单屏应用程序。一切看起来都很好,直到我需要添加更多屏幕。一页应用程序显示正确,但当我添加屏幕时,BoxLayouts 不再按我的预期工作。所有小部件都在屏幕底部呈现
我正在编写一个 kivy 程序/游戏。我以前也做过一个,不过总共只有一屏。我已经开始开发一个新程序,其中包含实现屏幕管理器的想法。我设法在 python 文件内构建了屏幕管理器,但它不适合我的长期使用
试图让我的 kivy 与 screenmanager 和 scrollview 一起工作。我不明白为什么它不起作用。如果我删除 ScrollView 并将其保留为一个简单的框和按钮(如代码中的屏幕 2
我正在为我的游戏设置屏幕管理器,但它没有按我想要的方式工作。我开发了在传递给此屏幕管理器的 JFrame 上在全屏和窗口之间切换的方法,但它给了我不应该出现的错误。为了获得独家全屏,我想通过 setU
我正在尝试使用 Kivy 并尝试将 ScreenManager 实例嵌套在 BoxLayout 中。我遇到的问题是,当 ScreenManager 是 BoxLayout 的子部件时,ScreenMa
我正在尝试弄清楚如何仅在按某个按钮时更改 kivy 中的屏幕方向动画(取消按钮应该像向前导航按钮一样向右删除而不是向左删除。)这是我目前正在做的事情实现这一点: # Cancel Button
如果在带有 DropDown 的屏幕之前有屏幕,我在使用 ScreenManager 和 DropDown 时会遇到可重现的困难。我已经为此苦苦挣扎了好几天,因为我是初学者,我认为这是我的错。 我将代
我曾在这里发表过一篇文章(触发 screenmanager 从 if 条件更改 Kivy 中的屏幕),尝试以不同的方法执行相同的任务。我在那里没有得到任何解决方案,所以我正在尝试不同的方法。但是,我现
如标题所述 - 我被卡住了。我一直在研究代码,只要我将 ScreenManager 和 Popup 分开,一切都会正常进行。一旦合并 - 他们拒绝合作。无论如何,这是显示我遇到的问题的简单应用程序。
我正在尝试使用 kivy,开发一个应用程序来注册锻炼程序,并在屏幕管理器中使用几个屏幕。但是,运行代码时,我收到 ScreenManagerException: kivy.uix.screenmana
我是 kivy 新手,需要 ListView 和 ScreenManager 方面的帮助。我设法在单个屏幕上使用 ListView,但我尝试通过 ScreenManager 在两个屏幕上使用它:我在主
完美的功能代码: from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import S
我正在 kivy 中使用屏幕管理器制作一个应用程序,但我被困在这里。我是 kivy 和 python 的新手。据我所知,我所做的一切都是正确的。 错误说 - kivy.uix.screenmanage
我是一名优秀的程序员,十分优秀!