Reputation: 7316
Heres my py file called loginscreen.py
from kivymd.app import MDApp
class loginscreen(MDApp):
def on_start(self):
loginscreen().run()
here's my kivy file called loginscreen.kv:
ScreenManager:
id: screen_manager
Screen:
name: "screen1"
MDLabel:
text: "HOT"
size_hint_y: .5
size_hint_x: None
width: 200
height: self.texture_size[1]
halign: 'center'
Screen:
name: "screen2"
MDLabel:
text: "COLD""
size_hint_y: .5
size_hint_x: None
width: 200
height: self.texture_size[1]
halign: 'center'
And here's my terminal output:
/usr/bin/python3 /Users/loginscreen.py
[INFO ] [Logger ] Record log in /Users/.kivy/logs/kivy_20-07-19_146.txt
[INFO ] [Kivy ] v1.11.1
[INFO ] [Kivy ] Installed at "/Library/Python/3.7/site-packages/kivy/__init__.py"
[INFO ] [Python ] v3.7.3 (default, Apr 24 2020, 18:51:23)
[Clang 11.0.3 (clang-1103.0.32.62)]
[INFO ] [Python ] Interpreter at "/Library/Developer/CommandLineTools/usr/bin/python3"
[INFO ] [KivyMD ] v0.104.1
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_imageio, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL ES 2" graphics system
[INFO ] [GL ] Backend used <sdl2>
[INFO ] [GL ] OpenGL version <b'2.1 INTEL-14.5.22'>
[INFO ] [GL ] OpenGL vendor <b'Intel Inc.'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) HD Graphics 615'>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b'1.20'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
[INFO ] [GL ] NPOT texture support is available
Process finished with exit code 0
Can someone explain to me why i cant get the kivy window to open when i hit run? on my main.py file, the window opens just fine, but not this one. What gives?
Upvotes: 0
Views: 613
Reputation: 64
Haha, My man, the answer is simple. Focus on the 4th line of code. Python is all about indentation (Spaces)
from kivymd.app import MDApp
class loginscreen(MDApp):
def on_start(self):
loginscreen().run()
You see, the error is that you put loginscreen().run() inside the loginscreen() class. Hence the interpreter couldn't read it. You need to put it outside the class.
A better way to write this code would be:
from kivymd.app import MDApp
class loginscreen(MDApp):
def on_start(self):
if __name__=="__main__":
loginscreen().run()
Adding the main class removes clutters and clarifies code a lot.
There's another error in your kivy file: Under screen 2 You have put an extra " after the MDLabel text. Remove that to avoid any future error
Upvotes: 0
Reputation: 29450
You didn't write any code that would start the app. Write loginscreen().run()
at the bottom of the file, not within the on_start
method as nothing will ever call that (nor would it make sense to start one app within the on_start
of another).
Upvotes: 1