Kivy Tutorial #7 - Touch Input/Mouse Input

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

Key Takeaways

Handles touch and mouse input in a Kivy application

Full Transcript

hey guys and welcome to another Kibby tutorial so in today's video I'm gonna be showing you how we can get kind of mouse input and also uh like finger input so like if someone was for it to example touch the screen with their thumb or like drag something around or whatnot this will work for all of that and then I think in the next video just give you a quick kind of summary of what's going on I want to get into drawing some things so for example maybe you want to use kevie for some kind of game development or something like that how can we draw kind of object shapes move those around and then we'll get into probably some more advanced stuff like creating multiple windows creating better applications where for example if you get the correct correct login it brings you to a page that gives you like your secret notes or something I don't really know exactly what I want to do but if you guys have any ideas please don't hesitate to let me know I'm thinking maybe sometime in the future I want to build kind of like a big GUI with this and walk you guys through how to really go into developing a proper application with Gibby but no promises on that it just kind of an idea that I had in my head so today we're getting input so we need to do actually is we're gonna have to re import our widgets so from kv2 IX start widgets import and will just import widget like that I'm sorry this is widget in case you didn't read along and what I'm gonna do is I'm gonna create this class so I'm just gonna create class I'm gonna call it touch it's gonna stand for like getting our touch input it's gonna inherit from widget and then in here I'm gonna define a few functions and we'll go through and talk about what they are so the first one is gonna be on underscore oh and then you can have it here on touch down okay and let's define another one so define on touch move and what define on touch up like that perfect so we've already got three so we can just pass in here for right now but essentially what these functions are gonna do is they have one input parameter right so we have touch and what's just gonna happen is essentially when we touch down on the screen we will get the position or we'll be able to get the position of where we pressed and a few a few other piece of information as well we're not gonna really use those and then same thing with move and up so when we're moving while touching the screen we'll be able to get that information and then if we release will not be able to see where we released when we release but not so some useful functions and again since we're inheriting from widget this means that these functions just work on any what do you call it like a grid layout box layout float layout whatever you're using these work on those and yeah so we'll talk about that in a second so I'll just go in rkv file I want to just create a small window here so actually sorry back to the kibbeh file let's return touch first we don't forget let's go to the KB file and what I'm gonna do in here is I'm just gonna say touch and in here I'm just gonna create a button just to prove to you that indeed we can put things inside alright so we'll do button say text equals say my BTN why not and that's all we need for a kibbeh file I just want to add something to the screen so for on touch down obviously that means like we press down or we click the mouse button down so all I'm gonna do is I'm just gonna print and we'll say no stone and then we can just print out touch and if we do this it'll print out like the position of the touch for us okay so same thing with on touch move will print mouse move okay and then we'll print touch again and I assume you guys can probably guess what we're gonna be printing here we'll say Mouse up and touch okay so let's run this and just see invalid property name yes text equals I'm sure you guys all saw that and got mad at me so text : now let's run this we have my button obviously here and just look in the console in the bottom left while I'm doing this when I press Mouse down mouse up gives us the s position and the position s position I believe stands for like relative position where this is like the absolute position so that's actually useful because for example like with our float layouts maybe we were like 30 percent X we don't know the actual X value of that button so we'd want to use the S position to figure out where our mouse is just now notice if I drag along it should keep going yeah you can see that just spamming mouse move because I was just dragging along the screen and then we get excuse me there we get mouse up at the bottom so you can see how that works now just something to notice here if I do try to click my bud it's no longer actually clicking like it's not highlighting and that's because and I believe this is the reason someone correct me if I'm wrong but when we have like we override this what do you call it this function mouse down this function already exists and this would he call it a touch movie or what not they already exist inside of this widget class and when we create them in here what we're doing is we're overriding the functionality of the function that's in the widget class so usually what would happen is on touchdown that function would trigger the let's say button to change colors right so what we're doing essentially when we override this is we're changing that functionality and we're removing all the functionality the other function and implementing our own so if you wanted our button to change like state when we clicked it what we'd have to do is we have to import this object property so you know what let's just do it so from Kirito properties import object property and then remember how we create an object property so let's just say bt m equals object property we'll say none and i believe in the QB file we just got to create a global variable here so let's say b TN equals BTN ah does it : yeah it gets : we'll see though and I will say ID BTN now we can do is we can say for example on touchdown will say BTN dot uh what was it BT and maybe color opacity opacity we can try that equals 0.5 and we'll see if this works I could have just absolutely butchered that BTN it's gonna be self that BTN opacity go pass it there you go okay so let's run this and when I click it now you can see that the opacity changes now obviously I would probably want to well actually change this opacity back when we release the button so that's a afterthoughts will do a past equals one and now if we click it we hold down we release it now our button is actually pressing properly like it should have been before so that's how you can do that I know it's not an ideal way to kind of fix that but when you override these functions that's what you have to do so I knew this has been a short video but this is all I'm gonna show for right now in the next video we'll get into some more advanced stuff I want to do some drawing we're gonna mess with this more if you guys have any ideas for any videos other videos you'd like to see please let me know and with that being said I'll see you guys in another video [Music]

Original Description

In this kivy tutorial 2019 I talk about getting user input such as touch input and input from the mouse. This way of getting input will work on all devices (phone, computer etc.). Text-Based Tutorial: https://techwithtim.net/tutorials/kivy-tutorial/touch-input-mouse-input/ 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 - Input kivy - Python kivy tutorial - kivy input - Python Tutorials
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

Up next
Brandjet Review 2026: AI Platform that Automates Your Outreach? 🔥
DroidCrunch
Watch →