Kivy Tutorial #9 - Navigation Between Multiple Screens

Tech With Tim · Beginner ·🛠️ AI Tools & Apps ·7y ago

Key Takeaways

Navigates between multiple screens using a screen manager in Kivy

Full Transcript

hey guys and welcome back from the kV tutorial so in today's video we're gonna be going through how to change screens so essentially having multiple windows and then doing some kind of transition between them based on like an event occurs so the exact example that I'm gonna be using is we're gonna have a login form and if you type in the password correctly it'll move you to the next page if not then obviously it won't move you there so this is actually quite a few steps so make sure you guys follow along closely and as always all the code will be up on tech with Tim net ok so what we're actually gonna start by doing is something different that we haven't done yet so notice that I change the name of my main app I've just deleted essentially everything there's nothing in my KB file to my main app instead of just my app so now this Cavey file won't actually load incorrectly if we remember the naming conventions from before so what I want to do is only use something called a builder which will allow us to load in the KB file no matter what the name of it is so let's just start by importing it so I leave us from K V dot Lang we're gonna import builder and then what we're gonna do is just type right above our class we'll say K V equals builder if I could type load underscore file believe that's the name and then what we'll do is put the name of our file so my dot K V and what we're gonna do now is we're just gonna return K V from this my main app so essentially what this is gonna do is this she's gonna load up this file it doesn't matter what the name of this file is now and we're gonna return this file when we're building the app so like let's just do an example here if I say button and I say text and we'll just go like Tim and to see if this works just to test and there we go we see we get a button Tim and again because we're loading up this KB fall it's the way this builder thing works just you don't have to name your K V file like the same thing as the class ok so that's it for Builder so what we're gonna do now is since we're setting up screens we actually have to use something from Kibby which is well screens and screen managers what we're gonna do is going to say from Kivi dot UI x dot screen manager import screen manager and import screen so we're gonna set up three classes and they're not gonna have anything inside of them but they're just gonna dictate our different screens and then our screen manager so our first class will be our first window so I'm just gonna say this main window okay and this is just gonna inherit from screen and then all we have to do in here is just pass now I'll actually copy this and paste this and instead of having main window we'll do second window and then we'll paste this one more time and against the main window we're gonna do what is it window manager the names of these don't really matter as long as you remember what they are and that instead of screen we're gonna do screen manager okay screen manager so essentially what this is gonna do now is this is gonna represent our main window which is our login form this will represent the page we go to next and this window manager will just represent like the transitions and stuff between the windows okay so what we're gonna do now is what we will I think we may be done actually for the Python file so let's move over to the kV file and start setting some stuff up so the first thing we need to do is we're just gonna grab this window manager and we're gonna set what type of screens are what screens are going to be inside of this so the two screens we have our main window okay and then we also have a second window right so we'll put those in here like that and just leave these as you need a colon here and we're not gonna type anything else but you just need the colon because there is possible options you could put so this right now is just saying we're gonna have two windows main window in second window if you wanted to add a third window you do something like third window here if I could type this and yeah then that's how you do that but you'd also have to make sure that you have a third window class here and I think you guys probably get the point so what I'm gonna do now is I'm just gonna start creating the kind of forms for our different windows now this is really similar to what we've done before except we just need to add a few other things to it so essentially what we're gonna do is gonna go May in the window like this and then in here what we'll put is uh first need to give it a name now the name is gonna be how we what do you call it call it in terms of moving between screens so the name of this one we'll just call this main now we'll even just we'll just the second window right now so we don't forget so second window and it's for the name here we'll just do second okay now again these names can be whatever you want just make sure you remember them because we are gonna have to use them so name main names second now all I'm gonna do in the second window notice - it's already here is just create a button and on my button all I'm gonna do is just have some text and that Texas is gonna say go back right because if we make it to this screen then we just want to be able to navigate back to the other screen so that's what we need for second window now for main window I want to set up this login form that essentially all it does is is just gonna have like a label a text input box and then a button so we're gonna do this similar to what we've done before with multiple grid layouts so in case you forget we're gonna do a grid layout and then for the first grid layout we're gonna have calls is one okay and then what should we put inside here we need to put another grid layout so the other grid layout will be calls too and then inside here we're gonna have a label and Wow okay I don't know what I just clicked to do that that was interesting and we'll say text and for this we'll just say is password okay colon and then we'll put a text input box and we're gonna need to give this an ID so the ID for this I'll just say is passed W okay and then in here what we'll do is we'll say for text input multi-line equals false okay so that's all we need for here now we actually know we need to add a button sorry give me on that one so add a button and this button is just gonna have a text that says submit and we're gonna have an on press event which were actually on release event which we'll do in just a second and we're gonna have a non release event here so let's just do that so we don't forget let's do a quick summary of what we've done so essentially this is all like this is probably a review except for this part here of what we've done before so we just created a very basic form all we're going to do is we have what do you call it the text input which is going to just ask you for a password you can type and password and then we're just gonna check here if the password is a certain value and if it is then we're going to transition to the other window so the way that we transition to the other windows is we you this we do app JA root dot current okay and then we set it equal to the window we want to go to so in this case if we hit submit we want to go to the second window that that is this right now the name of that window is second like we named it here so that's all we're gonna do we're gonna say app dot root current equals second now we can actually copy this and we can paste it right here as well and here though if we want to go back we won't want to do the name main so that's what we'll do and actually let's just tab this in here underneath on release and this should be working fine so let's run this quickly and assuming I didn't make any mistakes which I probably did we should be working invalid property property name multi-line I can't do equals false I have to do : false believe that's the issue yes there we go okay so we have a little login window make it a bit smaller you can see it resizes so I'd type something in here hit submit and you can see it brings me over to my other page and then if I hit go back it brings me back now notice though that these transitions are probably not ideal moving like left right or just keep moving to the left but we want to go left and then to the right so how do we do that well luckily there is a way that we can do that so on the release here what we're actually gonna type in type root dot manager dot transition assuming I spell this correctly so root dot manager dot transition dot direction and then this is gonna be equal to what direction I wanted ghost in this case we're gonna go left okay and then if we copy this and we paste it here we can go right so now let's check this out and see if I did this correctly okay so if I hit submit you can see removing to the left now watch this if I hit go back we move to the right so you can see that it's kind of going back and forth and that's awesome okay so the last thing I want to do for this video is I want to make it so it only lets us go to the next page if we type this password correctly right so how can we do that well we just need to do a little bit of logic inside of here so the reason we gave this an idea so that we can check the value so on on release here let's go in here and let's do a bit of logic let's just say if or we'll say second if and I will say Pass W dot txt equals equals and let's just make the password Tim in this case we'll say else we're just gonna stay on this main page so we'll go to second if the password is Tim otherwise we'll go we'll just stay on the main page okay so let's try this if I hit submit I'm not typing a password it's not working if I type T I doesn't work if I type Tim you can see we go to the next page and that is essentially oh we should probably actually would want to clear this as well so we could do that too you know what let's not worry about that right now how am I do in the next video but essentially that's how that works this is how we can go between multiple windows if you want to create another window create another class inherit from screen same thing here and then you can kind of lay out the navigation for yourself so if you guys enjoyed the video please make sure you leave a like and subscribe and I will see you again in another one [Music]

Original Description

This kivy tutorial covers navigating between multiple screens using a screenmanager in kivy. It will show you how to create multiple windows/screens and transition between them. Text-Based Tutorial: https://techwithtim.net/tutorials/kivy-tutorial/multiple-screens/ Kivy Docs: https://kivy.org/doc/stable/ ************************************************************** WEBSITE: https://techwithtim.net proXPN VPN: https://secure.proxpn.com/?a_aid=5c34b30d44d9d Use the Code "SAVE6144" For 50% Off! One-Time Donations: https://goo.gl/pbCE9J Support the Channel: https://www.patreon.com/techwithtim Podcast: https://anchor.fm/tech-with-tim Twitter: https://twitter.com/TechWithTimm Join my discord server: https://discord.gg/pr2k55t ************************************************************** Please leave a LIKE and SUBSCRIBE for more content! Tags: - Tech With Tim - Kivy tutorial - Multiple screens kivy - Python tutorial kivy - Python kivy - Kivy - Python Tutorials - Kivy screenmanager
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Tech With Tim · Tech With Tim · 0 of 60

← Previous Next →
1 A* Path Finding Algorithm(Visualization)
A* Path Finding Algorithm(Visualization)
Tech With Tim
2 Python Programming Tutorial #1 - Variables and Data Types
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
3 Python Programming Tutorial #2 - Basic Operators and Input
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
4 Python Programming Tutorial #3 - Conditions
Python Programming Tutorial #3 - Conditions
Tech With Tim
5 Python Programming Tutorial #4 - IF/ELIF/ELSE
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
6 Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
7 Python Programming Tutorial #6 - For Loops
Python Programming Tutorial #6 - For Loops
Tech With Tim
8 Python Programming Tutorial #7 - While Loops
Python Programming Tutorial #7 - While Loops
Tech With Tim
9 Python Programming Tutorial #8 - Lists and Tuples
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
10 Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
11 Python Programming Tutorial #10 - String Methods
Python Programming Tutorial #10 - String Methods
Tech With Tim
12 How to Overclock a NVIDIA GPU
How to Overclock a NVIDIA GPU
Tech With Tim
13 Python Programming Tutorial #11 - Slice Operator
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
14 Python Programming Tutorial #12 - Functions
Python Programming Tutorial #12 - Functions
Tech With Tim
15 Python Programming Tutorial #13 - How to Read a Text File
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
16 Python Programming Tutorial #14 - Writing to a Text File
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
17 Python Programming Tutorial #15 - Using .count() and .find()
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
18 Python Programming Tutorial #16 - Introduction to Modular Programming
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
19 Python Programming Tutorial #17 - Optional Parameters
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
20 Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
21 Python Programming Tutorial #19 - Global vs Local Variables
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
22 Python Programming Tutorial #20 - Classes and Objects
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
23 Cool VBS Script to Prank Your Friends!
Cool VBS Script to Prank Your Friends!
Tech With Tim
24 How to Overclock an AMD GPU
How to Overclock an AMD GPU
Tech With Tim
25 Best GPU'S For Mining Ethereum (2018)
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
26 Recursion and Memoization Tutorial Python
Recursion and Memoization Tutorial Python
Tech With Tim
27 Ethereum Mining Rig - Hardware Guide
Ethereum Mining Rig - Hardware Guide
Tech With Tim
28 Pygame Tutorial #1 - Basic Movement and Key Presses
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
29 How to Install Pygame (Windows 8/10)
How to Install Pygame (Windows 8/10)
Tech With Tim
30 How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
31 How to Mine Ethereum 2018 - WORKING (Super-Easy)
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
32 Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
33 Pygame Tutorial #2 - Jumping and Boundaries
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
34 Pygame Tutorial #3 - Character Animation & Sprites
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
35 Pygame Tutorial #4 - Optimization & OOP
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
36 OBS Studio Tutorial - Best OBS Settings
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
37 Linear Search Algorithm - Python Example and Code
Linear Search Algorithm - Python Example and Code
Tech With Tim
38 Make Any Mic Sound AMAZING! (WITH OBS)
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
39 Binary Search Algorithm - Python Example & Code
Binary Search Algorithm - Python Example & Code
Tech With Tim
40 Pygame Tutorial #5 - Projectiles
Pygame Tutorial #5 - Projectiles
Tech With Tim
41 Pygame Game - Mini Golf
Pygame Game - Mini Golf
Tech With Tim
42 Pygame Tutorial - Projectile Motion (Part 1)
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
43 Pygame Tutorial - Projectile Motion (Part 2)
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
44 Pygame Tutorial #6 - Enemies
Pygame Tutorial #6 - Enemies
Tech With Tim
45 Pygame Tutorial #7 - Collision and Hit Boxes
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
46 Pygame Tutorial #8 - Scoring and Health Bars
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
47 Cloud Mining vs. Hardware Mining - 2018
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
48 How to Install Pygame on Mac OSX (Fast-Simple)
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
49 Pygame Tutorial #9 - Sound Effects, Music & More Collision
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
50 Pygame Tutorial #10 - Finishing Touches & Next Steps
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
51 How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
52 How to Create a Button in Pygame [CODE IN DESCRIPTION]
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
53 Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
54 Pygame Side-Scroller Tutorial #2 - Random Object Generation
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
55 Pygame Side-Scroller Tutorial #3 - Collision
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
56 Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
57 How to Create A Message Box in Python - Tkinter
How to Create A Message Box in Python - Tkinter
Tech With Tim
58 Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
59 How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
60 Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim

Related Reads

📰
3 Free AI Tools I Use to Save Hours Every Week
Discover 3 free AI tools to automate repetitive tasks and save hours every week, boosting productivity
Dev.to · Hari Haran
📰
My AI Bill Dropped 95% When I Switched to Chinese Models
Switching to Chinese AI models can significantly reduce costs, with one company experiencing a 95% drop in their AI bill, making it a viable option for businesses looking to cut expenses.
Dev.to AI
📰
AI Dubbing for Short Drama: The 2026 Playbook That Actually Scales
Learn how to scale AI dubbing for short drama with the 2026 playbook, improving efficiency and quality in audio post-production
Dev.to AI
📰
Why AI App Backends Are Becoming Accounting Systems
Learn how AI app backends are evolving into accounting systems and why it matters for SaaS businesses
Dev.to · StructureIntelligence
Up next
Advanced Tutorial NotebookLM Slides For Powerpoint
Russell Stannard (TTVideos)
Watch →