Kivy with Python tutorial Part 3 - The Kivy .kv Language

sentdex · Beginner ·🛠️ AI Tools & Apps ·11y ago

Key Takeaways

Introduces the Kivy .kv language

Full Transcript

hello everybody what is going on Welcome to the third K with Python tutorial Basics video in this video we're going to be talking about the KE language so this is where you might see these KV files now it's actually the case that you don't ever need to use the KV language uh it's really there for just for you if that's what you want to use but you can actually write the identical application using pure python code uh so as you can see here we've actually we've utilized some keie language only we've written it in pure python but what you can do is you can use these KV files uh to maybe better organize uh your presentation of the guey and keep the python files for the logic so depending on which way you think you might want to use things separately but again it might actually be the case that your application or your program is simpler if you keep it all together in just pure python or uh if you're using a lot of customization or maybe you're using a lot of customization but a lot of that customization is very redundant then it would make a whole lot of sense to use the KV files so uh I think you can get a by using you know doing one or the other it really doesn't matter uh but in programming in general there's a million different ways to do something and everyone has their opinion on what the best way is and they'll ridicule you if you disagree um so I'll go ahead and show both versions here but honestly don't worry about what other people say is the best just try them both out see what fits best to you uh and use that so anyway that's what we're going to cover here is the KY language so uh the first thing I'm going to do is I'm just going to go ahead and we'll get rid of this we're not going to be using it for now and even we don't need these Imports anymore either so this is kind of one of our our initial um scripts only the only difference here was this was label and uh the parameter was text and it said hello world like this okay so we'll save and run that and that was our original application if you recall so uh that's that and this is you know written in pure python now what if we wanted to write this or at least utilize the kyv language so uh what I'm going to do is I'm going to use notepad Plus plus if you don't have it I highly suggest uh you get it you could write all this in just a regular notepad file and then use the same saving practices that we're about to use but anyway so within your kyv uh file here what you can do is it's always a good idea to reference the file that you are um kind of like associated with because as you'll see in a second um the way that the python script is going to know the KV file to use is really kind of screwy um I'm not quite sure why they went with the way that they went but they did so anyway so we'll just say you know file name and this is going to be uh in conjunction with our KV video3 for example so KV video3 dop put whatever your file name is um you can require a kyv version here by using the um hasht colon uh and then we can say kyv uh 1.8.0 and that will also put a requirement for the the kyv language file so uh now let's kind of consult here we've got you know Simple kyv app we've got a label and it says text hello world so you can kind of envision your KV files I someone's going to like jump down my throat for this but the KV files are a lot like CSS right so it's a lot like having a stylesheet okay and so just like with HTML and CSS you can kind of write you know text attributes right in the paragraph tags let's say for example and you can give kind of some style attributes to it or you can have a style sheet that says hey everything with a paragraph tag class article right looks like X right it looks like this or you can actually you don't even need a CSS sheet you could always just create custom Styles as you went like we can see with websites it makes a whole lot of sense to have a style sheet so you don't have to continuously keep using classes Now with uh applications depending on the application if you have a small applic or you don't have a lot of redundancy it sometimes it actually I think is a little simpler to use it within the application at least for me but um again it doesn't matter which one you use both of them are very effective and both of them will work in the way that you expect them to so anyways this is a KV file KV uh requirement now how would we do this well like a CSS uh stylesheet first you're going to have you know the attribute so to speak so for us it's going to be we want to say label now what this is BAS it's a parent okay so this is referencing anytime we use labels so that's referencing right here but you could take it a step further and add other attributes within here we are going to do that but you could actually have a button or like other stuff within here that would be a child of a label so every child of a label with X attribute would be a certain way but anyway not to get too far ahead of ourselves uh I'll we'll show that when we get there but anyway so label 1 2 3 4 just use the same kind of indentation PR practices and then you can have your actual values here so text we're saying text colon uh and then we can say hello world like this now that's it that's all we're going to add right this instant and what we can do now is we'll go file uh save as and I'm going to save mine um we'll go save file type as and go to the very top and we'll say all types so this gets saved here is like all types like that and then what we're going to do is we're going to save this as uh simple kv. KV okay so we'll hit save and then instead of return uh label and then specifying an attribute let's just say return label so there's nothing else there so we'll save that and let's go ahead and run that and see if we work no we didn't work hold on let's see what it says apparently simple kv. okay well I guess it didn't want us to be all C or to do camel casing uh let's go where oh here it is okay so it was yelling at me for the camel casing so I'm going to un camel case here so simple KV or simple KV under like all undercase so I called it capital S capital K for some reason it didn't like that I don't recall that being an issue before man it's still getting angry at me simple kiwi I'm looking at it man I don't know why you're telling me you can't find it CES desktop SX lessons Ki slash simple KY oh it's not a DOT oh my goodness okay uh simple kyv now I'm going to go back I had used apparently a let's try this one more time okay save and run that there we go okay so that's that's why okay so the the problem was actually instead of dot KV I hit comma KV apparently so the camel casing was fun I just reverted it back to the cam casing actually so now you can see we have our application hello world um just the same as it was before it's just now we're referencing this label now before we move too much further I do want to show that uh this one yeah there's the comma it's kind of really hard to see actually that it is a comma um I'll just say no there and let me open this up one last time and interestingly enough the KV language is kind of like a I don't know hybrid of python almost and so what you can actually say is text equals hello world but what if we said text equals for example hello world and hello plus space world let's say so we'll save that and we'll run it and you still see that we have the exact same hello world then what we can do is we can go even further and we can do Hello uh world and uh uh comma 1 + one see if we get away with that we're in untested territories at the moment I got angry okay uh oh it only accepts a string okay that's fine so anyway we'll come back over here um so that was that's actually a parameter issue so let's let's do string 1+ one let's see if we get away with that version at least um still angry with me are you serious I converted it to a string you're a you make me very angry um okay well apparently with our text labels uh it's very stringent as far as uh that it just wants text elements only but uh when you're not let's say you're not using the text element you can actually incorporate python Logic on the other side of the colon so at least you can see here with the plus we've Incorporated some uh python logic but again this one's very stringent and it only wants text but maybe later I'll show you guys uh some actual logic uh within our KV uh language here but like I said I I think the only reason you would use this KV is strictly to actually separate the logic um and make the KV file just presentation and the python file just logic but anyway uh that's that so if you guys have have any questions or comments please feel free to leave them below otherwise as always thanks for watching thanks for all the support and subscriptions and until next time

Original Description

In this Kivy application development tutorial, we cover the Kivy (.kv) language. The idea of the .kv files is to separate your presentation from your logic. sample code: http://pythonprogramming.net http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related Reads

📰
The Ultimate Guide to AI-Powered Resume Building: Create Your Perfect Resume in Minutes
Learn how to create an AI-powered resume in minutes with this comprehensive guide, streamlining your job search with ATS-optimized resumes.
Dev.to AI
📰
I Used AI Every Day for 30 Days — Here’s What Happened
Learn how using AI daily for 30 days can boost productivity and workflow efficiency, and discover the benefits and downsides of AI integration
Medium · AI
📰
Building Custom Prompts: Crafting Instructions for Your Specific Patent Art Area
Learn to craft custom prompts for your specific patent art area using AI, applying the principle of specificity to achieve better results
Dev.to AI
📰
About Ebuhu
Explore Ebuhu, a website about AI, programming, and web development, to enhance your skills in these areas.
Medium · AI
Up next
I Tested Every AI Content Tool - Here's How to Use Poppy AI (Complete Beginner Tutorial)
Poppy AI
Watch →