Reputation: 85
I have a realy simple program in Kivy with 3 windows.But when I run it it says
The file C:\Users\ab79\Documents\GPX WEATHER\weather.kv is loaded multiples times, you might have unwanted behaviors.
I can run it but there is actually an unwanted behaviour, one of my three windows desappears ! When I run the code now it is skipping the "infoWindow" in the middle. I can observe it since I put FloatLayout instead of GridLayout, but the error message was already here before. I don't understand what's going wrong.
Here is the minimal code
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()
Kivy
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 ?
:)
Upvotes: 1
Views: 2147
Reputation: 17
You have to assign full code of your 'kv' file in to a variable(ex:- kv = """kv code here"""). And create a new function to load it using Builder.load_string(kv)
. After that use 'kivy.clock' module to schedule that function once when the build method is started.
Upvotes: 0
Reputation: 38992
The file weather.kv
is loaded automatically, see documentation. But you are also loading it explicitly with:
kv = Builder.load_file("weather.kv")
I think you just need to delete the above line, and change your WeatherApp
class to:
class WeatherApp(App):
pass
Upvotes: 3