python - 如何解决Kivy中的“.kv多次加载”错误?
问题描述
我在 Kivy 中有一个非常简单的程序,有 3 个窗口。但是当我运行它时,它说
The file C:\Users\ab79\Documents\GPX WEATHER\weather.kv is loaded multiples times, you might have unwanted behaviors.
我可以运行它,但实际上有一个不需要的行为,我的三个窗口之一消失了!当我现在运行代码时,它会跳过中间的“infoWindow”。我可以观察到它,因为我放置了 FloatLayout 而不是 GridLayout,但是错误消息之前已经在这里了。我不明白出了什么问题。
这是最小的代码
Python
today = datetime.datetime.now()
class ImportFileWindow(Screen):
pass
class InfoWindow(Screen):
pass
class ResultWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("weather.kv")
class WeatherApp(App):
def build(self):
return kv
if __name__=="__main__":
WeatherApp().run()
基维
WindowManager:
ImportFileWindow:
InfoWindow:
ResultWindow:
<Label>
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
font_size:40
color: 0,0,0,1
<Button>
font_size:40
color: 0,0,0,1
background_normal: ''
<ImportFileWindow>:
name: "import"
Button:
text: "Importer"
on_release:
app.root.current = "info"
root.manager.transition.direction="left"
<InfoWindow>:
name: "info"
day: day
FloatLayout:
cols:2
size:root.width,root.height/2
Label:
text:"Jour :"
TextInput:
id:day
multiline:False
Button:
text:"Valider"
on_release:
app.root.current="result"
root.manager.transition.direction="left"
Button:
text:"Retour"
on_release:
app.root.current="import"
root.manager.transition.direction="right"
<ResultWindow>:
name: "result"
Button:
text: "Retour"
on_release:
app.root.current="info"
root.manager.transition.direction="right"
```
The error is are since the begining but the real issues are here since I use a FloatLayout instead of GridLayout.
Any ideas ?
:)
解决方案
该文件weather.kv
会自动加载,请参阅文档。但是你也明确地加载它:
kv = Builder.load_file("weather.kv")
我认为您只需要删除上面的行,并将您的WeatherApp
课程更改为:
class WeatherApp(App):
pass
推荐阅读
- node.js - 为什么我的快速会话变量在不同的路线上返回“未定义”?
- r - 在 R Shiny 中调用 tabPanel 时如何使用 lapply 或其他高阶函数
- html - 为什么我的每个循环在放入 mixin 时都不起作用?
- keras - 渐变的 Keras 自定义损失“无”
- multidimensional-array - 如何从外部数据映射深度嵌套的项目数组
- python - 如何查找不包含特定字母的单词?
- python - 如何按每行的第一个元素排序?
- javascript - owl-carousel - 如何使用每个下一个点滑动到第三张幻灯片 - .owl-dot:Active
- php - 当向函数传递的参数太少时,PHP 7 会抛出错误吗?
- angular - 为什么只显示 Angular 异步管道绑定中字符串的最后一个字符?