Hey fellow developers, in this video we're going to be creating a Python program to check the price of any cryptocurrency and display it to the user using a GUI, or a graphical user interface. We're going to be doing this in a super simple and easy way, and I'm going to be explaining everything step by step. Before we get started, I'd like you all to know that we're going to be using two modules, two Python packages for this program.
The first is requests, and the second is tickinter. The code editor I'm using for this tutorial is Visual Studio Code. For those of you who want... to install it you can head over to the link in the description and install Visual Studio Code onto your system.
Feel free to use any other code editor just make sure that that code editor supports Python content. And now if we go over a quick overview of Requests and Tkinter I'll leave the documentation for both the modules in the description but just a quick overview what both of them do for the beginners. Requests is basically a module that allows us to access and send HTTP requests to the web. and implement them into our programs and then Tkinter is used to create a GUI or a graphical user interface.
I'll walk you guys through how we set up a GUI using Tkinter later in the project, but yeah, let's get started. For those of you who might not have these modules installed, you want to head over to your Windows PowerShell command prompt or terminal. I'm on a Mac, so I'm going to be opening my terminal and here you want to type in pip install requests. Now I already have it installed, but for those of you who don't, hit enter and it's going to install it for you. And then you want to do the same thing with Dickinter, but we're going to be using an abbreviation for Dickinter, which is commonly accepted, that is TK.
So pip install TK, hit enter, and it's going to install Dickinter for you. That's pretty much all you need to run this program. And I'm going to be leaving one more API link in the description. An API is an application programming interface. And we're going to be using a CoinGecko API.
CoinGecko, just like many other cryptocurrency data providers, provides information on the active real-time prices of cryptocurrencies and a lot of other financial cryptocurrency data that we need to use for the program. So if we head over to Chrome, I have CoinGecko opened up here. You can see cryptocurrency prices by market cap, and it has almost all of them.
Bitcoin, Ethereum, Tether, Solana, and Dogecoin, and a lot of other cryptocurrencies over here. And we're also going to be using... the API, right this one, get your API key now. Now we have a pre made API key that we're using because we don't really need to access much.
So it's quite simple. This is all we're going to be using. And yeah, let's get started. So I'm going to start with the demo of the code, we're going to hit run.
And what it does is it opens up a GUI or a graphical user interface. And I'm just going to zoom this out a little bit, you don't have to, but I'm going to. And As you can see it has three sections over here.
The first is cryptocurrency. This is where the user inputs which cryptocurrency they want to check. Then we have price threshold.
Now the feature that I've implemented into this program is the user sets a price threshold and if the cryptocurrency the user chooses has a price that crosses the price threshold we get a notification. Now this is useful when you're monitoring daytime prices. So you can set when you're in day trading or in a lot of different things you can set the actual exact price that you want to know when it crosses, get a notification, and instantly do whatever you need to.
So for example, if Bitcoin is somewhere above $60,000 and I set the price threshold as $30,000, when I click on check price, the first thing I'm going to get is a notification saying that Bitcoin has crossed the price threshold, right? So this gives us real-time data of that exact second. So I'm going to hit check price for Bitcoin.
This is a button. And it says, first of all, we get the notification Bitcoin price has crossed $30,000. Okay. And then it gives us the price. That is $66,171 is the exact price of Bitcoin right now.
Now we can check other cryptocurrencies here as well. For example, Ethereum. Ethereum. We hit check price and it gives us the active price of Ethereum. which is 3561.41 us dollars now we can try a lot of different ones let's go with dogecoin click on check price and it gives you 0.136067 us dollars now that is how this program works it's super simple super easy and you can use it to implement a lot of financial programs uh into whatever you're building so and i'm gonna walk you guys through the code in a super simple and easy way let's just close this to kinter And right, so by the way what you guys just saw, a message box was the notification that we got.
I'm going to explain all of this. I have a file here called explanation.py which contains a brief understanding of what we're doing. So what you're going to learn through this program is fetching data from the internet.
Request module like I told you to send HTTP requests and get real-time cryptocurrency prices from the CoinGecko API We're building a simple user interface. I know it's not that great. It's very simple Nothing complicated and we're using to Tkinter to create that graphical user interface where we can enter the cryptocurrency name and price threshold.
Now, there's two things that the user is inputting, the cryptocurrency name and the price threshold. That's it. Nothing else is based on the user. And then we're handling that user input. And I've also added error management here.
basic error handling to manage incorrect inputs or missing data I'll just show you that I said in the code basically if it does not recognize the cryptocurrency what it does is it says cryptocurrency and then that crypto that the user has entered crypto is what the user enters cryptocurrency not found and that's what it returns through a notification now message box is the notification as I showed you guys so that's that's how it works and now the step-by-step guide that we have here the first thing you need to do is set it up so we need to import the necessary modules. So as you can see over here, import requests, import to Tkinter as TK, from to Tkinter import message box, right, and we need to Tkinter to create our GUI and we use request to fetch data from the internet. Fetching cryptocurrency prices, we'll write a function called getCryptoPrice which you can see right over here. This is the one that we implement the API in to get the price that takes the name of a cryptocurrency as input, so the user puts in the input, and returns its current price in US dollars.
using the CoinGecko API. Alright and then we just have the user interface to build the user interface we're using to Kinter to create a simple window where users can enter the cryptocurrency name and the price threshold as I explained earlier and then we add a button and this is quite important we add a button that when clicked will check the current price of the entered cryptocurrency and compare it to the threshold. Alright so this is where we have right over here One second.
Right. This is what we have right over here. And then what we do is we check the price and alert the user of the price.
So we write a function called check price that gets the current price, compares it with the threshold and displays a pop up message using message box from. to check if the price is above the threshold or not. Now it's pretty simple. I'm leaving this source code in the description for those of you who want to access it, along with this explanation for anybody who wants to use it further for educational purposes. And the reason I'm not not going into depth about each and every single line of code is because it is very self-explanatory for those of you who don't know python what we've done is we basically imported a couple of modules that we need i've explained the need for those modules on the left and then we're using we're setting a function to get the price of the cryptocurrency right over here line six we're getting the price of the cryptocurrency and we're using this api key right over here and this is basic and if the cryptocurrency is not found right what it does is it returns nothing and it returns the data of the cryptocurrency now we have error handling over here and right over here we have a loop so this will continue until you close the program it will not end so you can keep on entering multiple cryptocurrencies and get the prices for them now let's just try an error message once so i can show you guys how that works let me just run the program we get this right now let's say we want to see an error message uh i want to show you guys how we've done error handling in this so if i just type in a program that it would not recognize let's say mana right mana is a decentralized cryptocurrency uh from decentraland we click on we we type mana and we click on check price it is not going to recognize mana because the coin gecko api is not recognizing mana so what we've done is we've done error handling so it's going to give us a notification and the notification is that cryptocurrency mana not found as you can see here we have have mana in quotation and the reason we have that is crypto not found as you can see we've added that right over here in the error handling so if price is none if it does not find any price the message box shows an error message which is cryptocurrency not found and crypto is what the user has entered so go the code once or twice you will be able to understand it and this is the placeholder we've set it as crypto so when as bitcoin so when it whenever anybody opens the gui the gui they will find bitcoin and a placeholder of thirty thousand as a threshold but that is based on whatever the user enters so it's pretty much it I don't think there's anything else I need to explain I'll leave all the documentation source code and explanation in the description for those of you who want to check it out from there so yeah peace