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