How to create a website in Python - Python Flask tutorial - First basic website
Python is a very popular language right now. Many big companies are using it. Python is used in most of the fields. You can create softwares, basic games as well as websites in Python. In web development, Python's libraries are considered very good for making backends. Even companies like Netflix use Python in their backend.
Basically, there are two main Python libraries, with which you can learn wen development and create a backend for your site. First is Flask, the other is Django. Flask is a little simple.
Here I will show how you can make your first Python website with Flask...
Process
Install the Flask library, by running the command pip install flask in your terminal.
Then you are ready for making your first Flask App
To get your first app, Create a new file and paste the below code. This is the basic structure of a Flask application.
The Code
fromflaskimportFlask, app
importflask
app = Flask(__name__)
@app.route("/")
defindex():
return"Just testing! Hello Sir! I am a web app"
if__name__ == "__main__":
app.run(host="127.0.0.1", port=8080, debug=True)
Congratulations, you have made your first Flask app.
Now open the terminal and run the command flask run
Previous Post:
Make your own Web Browser in Python using PyQt5. PyQt5 is a very powerful Python framework to make modern GUIs. With help of Python PyQt5 QtWebWidgets, it is very easy to amke your own custom web browser with a few lines of code.
PyQt5 Basic code
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
# Main Window
super(MainWindow, self).__init__()
self.showMaximized()
app = QApplication(sys.argv)
QApplication.setApplicationName("Browser")
window = MainWindow()
app.exec_()
Make your own Web Browser in Python using PyQt5. PyQt5 is a very powerful Python framework to make modern GUIs. With help of Python PyQt5 QtWebWidgets, it is very easy to amke your own custom web browser with a few lines of code.
PyQt5 Basic code
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
# Main Window
super(MainWindow, self).__init__()
self.showMaximized()
app = QApplication(sys.argv)
QApplication.setApplicationName("Browser")
window = MainWindow()
app.exec_()
PyQt5 Browser code using QtWebEngine
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
# Main Window
super(MainWindow, self).__init__()
self.browser = QWebEngineView()
self.browser.setUrl(QUrl('https://google.com'))
self.setCentralWidget(self.browser)
self.showMaximized()
# nav bar
navBar = QToolBar()
self.addToolBar(navBar)
backBtn = QAction("Back", self) # back Button
backBtn.triggered.connect(self.browser.back)
navBar.addAction(backBtn)
forwardBtn = QAction("Forward", self) # forward Button
forwardBtn.triggered.connect(self.browser.forward)
navBar.addAction(forwardBtn)
relBtn = QAction("Reload", self) # Reload Button
relBtn.triggered.connect(self.browser.reload)
navBar.addAction(relBtn)
app = QApplication(sys.argv)
QApplication.setApplicationName("Browser")
window = MainWindow()
app.exec_()
The final look of the browser after the above code.
So, I think that's it for this post. See you in the next...
Make your own Python IDE + Text Editor like Notepad:
July 17, 2021, 4:33:43 PM (MrDev in a deep thought)
If you have used Python, you must be aware of the Python shell (the IDLE). We have one place where we write the code and to run the code, we need to switch between the windows. Some brilliant mind will say (with a sarcastic sound) "He calls himself a programmer and he is talking about IDLE... Lol hahaha."
Shut up! Okay? I use IDEs but something that you have made, even its worse than what you think that was worse, you will like that! And a programmer builds things. This is his work.
Now in this project, I created my own IDE with python using Tkinter.
Now let me assume that some of you are from Mars and they don't know what IDEs actually are? So basically, IDE stands for Integrated Development Environment. It provides a collection of different things needed for coding and creates an environment for coding fast. Well its obvious that I could not make something at once that can directly challenge VS code (one of the leading IDEs in). But I can make something more similar to a text editor (like Notepad). And basically, what we actually want in programming is a section to run the program and display the output. So, can't we combine the output and the editor part in the same window. So, it reduces our work to switch between the windows like we do in IDLE.
Well, that's all about the idea. I am going to create a new notepad. But don't laugh. Okay. It would have some more features than notepad. Believe me! Let's start!
>>> Test 1: ✔ >>> Test 2: ✔ >>> Test 3: ✔ >>> Test 4: ✔ ...
Python is among the most popular programming languages at this time. It is a fact that if you want to learn programming, the most important thing is to build your logic. Some people find problems in getting logic building programs. So, here are a few of my personal logic building programs you can see and build you rlogic. First, read the top comments (starting with # symbol at the top of programs). They tell what the below lines are going to do. Try to build your own logic after reading those comments. Then you can read my code to get some extra information. So, below are the programs you can have a look.
# program 1: that finds whether the entered no. is 1/2/3 digits
a = int(input("Enter a no.: "))
if a < 0 or a > 999:
print("Please enter a no. in range 1 to 999")
else:
if a<10:
print("The no. is a 1-digit number")
elif a<100:
print("The no. is a 2-digit number")
elif a<1000:
print("The no. is a 3-digit number")
# program 2: ask user to input numbers until entered 'done', then print the sum of all entered numbers.
c=0
while True:
a = input("Enter a no.: ")
if a == 'done':
print(c)
break
elif a != 'done' and a.isnumeric() != True:
print("invalid key command")
break
else:
c += int(a)
# Program 3: ask the day no. and the first day of a year. Then print the day on the day no. provided
_day = int(input("Enter the day no. from 2 to 365: "))
day_n = str(input("Enter the first day of that year: "))
day_list = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
if day_n in day_list:
a = _day % 7
for i in range(0, 7):
day_list_i = day_list[i]
if day_list_i == day_n:
for j in range (i, i+7):
day_var = day_list[(a+j)%7]
print(day_var)
else:
print("Please don't try to fool the program :')")
# Program 4: miles to k.m. conversion table
print("miles\t|\tk.m.")
for data in range(1, 11):
print(f"{data}\t|\t{data * 1.609}")
# Program 5: Print the stats of entered string (like total lowercase/uppercase characters adn no. of alphabets and numbers)
l = input("Enter a string: ")
lowercount = uppercount = alphabet = numbers = 0
for a in l:
if a.islower():
lowercount += 1
if a.isupper():
uppercount += 1
if a.isalpha():
alphabet += 1
if a.isnumeric():
numbers += 1
print(f"Lowercase: {lowercount}\nUppercase: {uppercount}\nAlphabets: {alphabet}\nNumbers: {numbers}")
So, I think that's it for this post. If you want to learn react follow the above playlist. See you in the next post.
So, as I meantioned in my last post, I started to learn React few months back. So, in this post I am going to show you the web app that I created in react. I learnt the same from the tutorials but I modified the code to remove some bugs. The name of the Website is TextUtyls
In this website, you can come and paste a part of text then use some tools in the text, at last copy the text. I know its very easy, but we start learning things from an easy project. And definitely, if you are going to make this, you will definitely learn a lot of things.
You can get the complete code of the website Click here
So, I think that's it for this post. If you want to learn react follow the above playlist. See you in the next post.
How To Learn React Step by Step:
React JS is a very popular web framework. It is a free and open-source front-end JavaScript library for building user interfaces or UI components. React JS is maintained by Facebook. So, if you are a web developer, you should be aware that everythin gwe see on the web is just html, css and the functioning things are simply javascript. You must have worked with html and css to make simple websites or standalone pages. But, what if you are building a large commercial website with many pages. There are a lot things to know about web development and many compplexitie4s in doing them like routing without reloading the pages.
So, React makes things much more easier and developer friendly to handle. Thus for a modern UI developer, you should learn this. Not only for UI, React helps in making a complete web app structure. This is not just for React. There are other JS libraries also like Angular, that you can learn to create modern web apps. But, in this post, we are discussing about React JS
So, a few months back from the time I wrote this post, I started to learn react. I followed a YouTube playlist that helped me. And if you are going to learn react then you can also follow it. But this is only if you know hindi. To access the playlist, click here.
This playlist makes you learn react by making projects. Which is I suppose the best way to learn programming. Like if you ask me, I never follow any tutorials. I just come across an idea and start building it. Yeah, most of the time I get frustrated as my ideas don't work. But this is how programming is. You learn to deal with problems. *Also, this is not a promotional post.*
So, I think that's it for this post. If you want to learn react follow the above playlist. See you in the next post.
So, in the last post, I made a IDE + Text Editor in Python using tkinter library. Part 1 In this post, I am going to make the designs a little better now.
Few days ago, I decided to make the IDE a little better. So, I started working on it, as always. Seriously, I am a beginner at Tkinter. I don't know much about app designing. Probablly this is my first Tkinter app :) So yeah, the designs are not great but they look a bit better.
Here's a look of the app
So, If you want to use the IDE, download the exe file here...
Presently, Pyhton is one of the most popular languages in the world. Its design philosophy emphasizes code readability with its use of significant indentation. Python is an interpreted high-level general-purpose programming language. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. Thus it is widely used in many fields such as data science, AI, ML. Python frameworks such as django and flask are also a good choice for designing the backend side of a website. Also there are frameworks such as Tkinter and PyQt5 for designing apps gui.
July 17, 2021, 4:33:43 PM (MrDev in a deep thought)
If you have used Python, you must be aware of the Python shell (the IDLE). We have one place where we write the code and to run the code, we need to switch between the windows. Some brilliant mind will say (with a sarcastic sound) "He calls himself a programmer and he is talking about IDLE... Lol hahaha."
Shut up! Okay? I use IDEs but something that you have made, even its worse than what you think that was worse, you will like that! And a programmer builds things. This is his work.
Now in this project, I created my own IDE with python using Tkinter.
Now let me assume that some of you are from Mars and they don't know what IDEs actually are? So basically, IDE stands for Integrated Development Environment. It provides a collection of different things needed for coding and creates an environment for coding fast. Well its obvious that I could not make something at once that can directly challenge VS code (one of the leading IDEs in). But I can make something more similar to a text editor (like Notepad). And basically, what we actually want in programming is a section to run the program and display the output. So, can't we combine the output and the editor part in the same window. So, it reduces our work to switch between the windows like we do in IDLE.
Well, that's all about the idea. I am going to create a new notepad. But don't laugh. Okay. It would have some more features than notepad. Believe me! Let's start!
>>> Test 1: ✔ >>> Test 2: ✔ >>> Test 3: ✔ >>> Test 4: ✔ ...
Tuesday, July 20, 2021, 3:01:27 PM (MrDev in a deep thought)
Finally, after adding a few things that clicked on my mind, I completed the IDE. This is the final look :)
So, I think that's it! If you want the code of this project, do let me know in the comments below! Right now, the link might not work.
If you want more like this, do let me know in the comments below... And Subscribe to this blog because I would be sharing more such projects of mine in future on this blog. Also, if you didn't see, check out my last project of a Music Player web app made in JavaScript. Click here
Then Bye Bye! Thanks for reading... :) See you!
In this article you will learn How can you make your own Like and Dislike system. We are going to make the logic in Php.
So if you don't know, PHP was a popular language for making websites backend. Even the world's biggest social network, Facebook was built in Php. But today, Php is not used much. Even its importance is decreasing day by day and it's becoming dead.
So Why did I made this in Php? Well the answer is simple. I know Php. Infact Php is a good language. You can even imagine the popularity of Facebook, which was made in Php. And its not bad to learn Php because if you are able to make the logics in it, it is definitely going to help you in other languages. There's no minus point for learning Php.
So, you must have seen like dislike systems on various social networks like YouTube. So 2 months back I wanted to create my own blog and I created it! I started from scratch and designed everything of it one by one as the ideas hit me. You can even have a look at it. TheShiveshNetwork I created this site piece by piece and designed it. And yeah this was my first complete website. With login system and few inbuilt features.
Well I know this site contains many bugs but they can be fixed by giving some time to them. Also I am telling this because I am not a kind of person who will keep you in confusion. I am still learning to code. But I love to build things and this site is for that.
The blog was getting completed day by day. So, the thing that I needed after a few days for this blog was a rating system. Where users can like or dislike the blog. So I started searching for tutorials on google and youtube to find the perfect thing that I wanted. Because I told, this was my first website so I needed a reference to understand how things are going to work.
After visiting many places, I couldn't find anything that could completely satisfy what I was thinking. The codes online even had lot of bugs. But one plus point, I had got my idea to use the things needed for making it and bring those things together. So, I started.
First of all, I created a mysql table to store the rating of posts. The table structure is as
Firstly, make a Mysql table named "posts"
Download
Then, make a Mysql table named "rating_info"
Download
Next, I connected to the mysql database in php and started writing my logic.
Finally, this was the thing I created. I was highly satisfied wuth its working. And I guess this is the best and complete like dislike system tutorial on the web with a free code. Just download, modify and use it. No need to waste your time on which I wasted weeks :)
Note: I have also combined login , signup and user authentication check and provided in the code below.
// The code. Just copy from here. Replace "
// initializing variables
$username = "";
$email = "";
$user_id = "";
$errors = array();
$db = mysqli_connect('localhost', 'root', '', 'test');
if (isset($_POST['reg_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
// form validation: ensure that the form is correctly filled ...
// by adding (array_push()) corresponding error unto $errors array
if (empty($username)) { array_push($errors, "Username is required"); }
if (empty($email)) { array_push($errors, "Email is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }
if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}
// first check the database to make sure
// a user does not already exist with the same username and/or email
$user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if user exists
if ($user['username'] === $username) {
array_push($errors, "Username already exists");
}
if ($user['email'] === $email) {
array_push($errors, "email already exists");
}
}
// Finally, register user if there are no errors in the form
if (count($errors) == 0) {
$password = md5($password_1);
$query = "INSERT INTO users (username, email, password)
VALUES('$username', '$email', '$password')";
mysqli_query($db, $query);
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: main.php');
}
}
// LOGIN USER
if (isset($_POST['login_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: main.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
if (!$db) {
die("Error connecting to database: " . mysqli_connect_error($db));
exit();
}
if (isset($_SESSION['loggedin'])) {
$user_id = $_SESSION['username'];
}
if (isset($_SESSION['success'])) {
// if user clicks like or dislike button
if (isset($_POST['action'])) {
$post_id = $_POST['post_id'];
$action = $_POST['action'];
switch ($action) {
case 'like':
$sql="INSERT INTO rating_info VALUES ('$user_id', $post_id, 'like')";
$sql1 = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='dislike'";
$result = mysqli_query($db, $sql1);
if (mysqli_num_rows($result) > 0) {
$sql = "UPDATE rating_info SET rating_action='like' WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='dislike'";
}
break;
case 'dislike':
$sql="INSERT INTO rating_info VALUES ('$user_id', $post_id, 'dislike')";
$sql1 = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='like'";
$result = mysqli_query($db, $sql1);
if (mysqli_num_rows($result) > 0) {
$sql = "UPDATE rating_info SET rating_action='dislike' WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='like'";
}
break;
case 'unlike':
$sql="DELETE FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id";
break;
case 'undislike':
$sql="DELETE FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id";
break;
default:
break;
}
// execute query to effect changes in the database ...
mysqli_query($db, $sql);
echo getRating($post_id);
exit(0);
}
}
// Get total number of likes for a particular post
function getLikes($id)
{
global $db;
$sql = "SELECT COUNT(*) FROM rating_info
WHERE post_id = $id AND rating_action='like'";
$rs = mysqli_query($db, $sql);
$result = mysqli_fetch_array($rs);
return $result[0];
}
// Get total number of dislikes for a particular post
function getDislikes($id)
{
global $db;
$sql = "SELECT COUNT(*) FROM rating_info
WHERE post_id = $id AND rating_action='dislike'";
$rs = mysqli_query($db, $sql);
$result = mysqli_fetch_array($rs);
return $result[0];
}
// Get total number of likes and dislikes for a particular post
function getRating($id)
{
global $db;
$rating = array();
$likes_query = "SELECT COUNT(*) FROM rating_info WHERE post_id = $id AND rating_action='like'";
$dislikes_query = "SELECT COUNT(*) FROM rating_info
WHERE post_id = $id AND rating_action='dislike'";
$likes_rs = mysqli_query($db, $likes_query);
$dislikes_rs = mysqli_query($db, $dislikes_query);
$likes = mysqli_fetch_array($likes_rs);
$dislikes = mysqli_fetch_array($dislikes_rs);
$rating = [
'likes' => $likes[0],
'dislikes' => $dislikes[0]
];
return json_encode($rating);
}
// Check if user already likes post or not
function userLiked($post_id)
{
global $db;
global $user_id;
$sql = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='like'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
return true;
}else{
return false;
}
}
// Check if user already dislikes post or not
function userDisliked($post_id)
{
global $db;
global $user_id;
$sql = "SELECT * FROM rating_info WHERE user_id='$user_id' AND post_id=$post_id AND rating_action='dislike'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
return true;
}else{
return false;
}
}
$sql = "SELECT * FROM posts";
$result = mysqli_query($db, $sql);
// fetch all posts from database
// return them as an associative array called $posts
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
?>
php tutorial - like dislike system
Have you ever tried to create a desktop notifications application based on your needs? do you know you can do this in a few simple steps using python?
In this project, we are going to make a custom notification system to remind us to take a break. Like, sometimes we spend a lot of time sitting on Computers doing our work. If you sit on Computers for ling time, you may be risking your health. So, we are going to make a reminder notification system to get up from your seat and take a rest after 1 hour is completed sitting on your computer.
So, that's all about it!
We just need one python library to make the code... plyer
Plyer is a Python library for accessing features of your hardware / platforms. We would be using notification of plyer to show messages.
Now let me explain the code. So basically, when the program runs, we start an infinite loop. Inside the loop, we have used notify function of notification. The first line sets the title shown above the notifiaction. Then we have message, in which we enter the string we want to display as message. Then there is app_icon. So, we can add the path of an icon image inside it. Just make sure the icon is in '.ico' format.
So I think that's all about this project. If you want more like this, do let me know in the comments below... And Subscribe to this blog because I would be sharing more such projects of mine in future on this blog. Also, if you didn't see, check out my last project of a Music Player web app made in JavaScript.
Click here
Then Bye Bye!
Thanks for reading... :)
See you!
Extra Reading:
A notification is about something (object = event, friendship..) being changed (verb = added, requested..) by someone (actor) and reported to the user (subject). Here is a normalized data structure (though I've used MongoDB). You need to notify certain users about changes. So it's per-user notifications.. meaning that if there were 100 users involved, you generate 100 notifications.
(Add time fields where you see fit)
This is basically for grouping changes per object, so that you could say "You have 3 friend requests". And grouping per actor is useful, so that you could say "User James Bond made changes in your bed". This also gives ability to translate and count notifications as you like.
But, since object is just an ID, you would need to get all extra info about object you want with separate calls, unless object actually changes and you want to show that history (so for example "user changed title of event to ...")
Presently, Pyhton is one of the most popular languages in the world. Its design philosophy emphasizes code readability with its use of significant indentation. Python is an interpreted high-level general-purpose programming language. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. Thus it is widely used in many fields such as data science, AI, ML. Python frameworks such as django and flask are also a good choice for designing the backend side of a website. Also there are frameworks such as Tkinter and PyQt5 for designing apps gui.
July 17, 2021, 4:33:43 PM
(MrDev in a deep thought)
If you have used Python, you must be aware of the Python shell (the IDLE). We have one place where we write the code and to run the code, we need to switch between the windows. Some brilliant mind will say (with a sarcastic sound) "He calls himself a programmer and he is talking about IDLE... Lol hahaha."
Shut up! Okay? I use IDEs but something that you have made, even its worse than what you think that was worse, you will like that! And a programmer builds things. This is his work.
Now in this project, I created my own IDE with python using Tkinter.
Now let me assume that some of you are from Mars and they don't know what IDEs actually are? So basically, IDE stands for Integrated Development Environment. It provides a collection of different things needed for coding and creates an environment for coding fast. Well its obvious that I could not make something at once that can directly challenge VS code (one of the leading IDEs in). But I can make something more similar to a text editor (like Notepad). And basically, what we actually want in programming is a section to run the program and display the output. So, can't we combine the output and the editor part in the same window. So, it reduces our work to switch between the windows like we do in IDLE.
Well, that's all about the idea. I am going to create a new notepad. But don't laugh. Okay. It would have some more features than notepad. Believe me! Let's start!
>>> Test 1: ✔
>>> Test 2: ✔
>>> Test 3: ✔
>>> Test 4: ✔
...
Tuesday, July 20, 2021, 3:01:27 PM
(MrDev in a deep thought)
Finally, after adding a few things that clicked on my mind, I completed the IDE. This is the final look :)
So, I think that's it! If you want the code of this project, do let me know in the comments below! Right now, the link might not work.
If you want more like this, do let me know in the comments below... And Subscribe to this blog because I would be sharing more such projects of mine in future on this blog. Also, if you didn't see, check out my last project of a Music Player web app made in JavaScript.
Click here
So, just if the case you are not aware of the chrome Dino game, let me tell you it is a chrome game. You must have seen this game once in your lifetime. If not, then may I ask you a question? Answer in the comments if you want, else ignore. I would like to ask "Are you from Mars?" No, it's not a silly question. It's very important. I want to know the answer. I am really serious.
The Dinosaur Game is a built-in browser game in the Google Chrome web browser. The player guides a pixelated Tyrannosaurus rex across a side-scrolling landscape, avoiding obstacles to achieve a higher score.
Search chrome://dino on Chrome browser and you will see the game.
Well, I think I am talking too much let's get straight to the topic...
Alert: Don't panic while running the code, just go to the python shell or the terminal (cmd/bash or anything on which the code is currently running) and press Ctrl+C to stop the running code.
So, for the project, the python modules/libraries I used in this project are pillow and pyautogui. Well, I think that pyautogui is one among few important libraries for automation of anything in python. Pyautogui allows you to automate the keys of your keyboard and even mouse. Just for an example, if you are going to subscribe this blog, then you can use Pyautogui to take your mouse and click on it. Isn't it awesome that this library makes that so easy. Also the other library I used is for image processing. Pillow is a image processing library.
Well, I also used time module to give a variation in hte project.
Let's understand the logic of the code to know the use of Pillow. The logic of the code is that the system takes few screenshots and then, just for easy processing, with the help of Pillow module, we convert the screenshots to grayscale image and then process for a particular color pixel in a space.
Basically, I have made a rectangular region with the coordinates of the screen. Now lwt's suppose, a dark black pixel comes in that rectangular region. The code will detect that and suddenly, with the help of pyautogui, we press the "up" arrow key. That's it. Now the point where the code becomes complicated is that, it depends on your systems processing power on how much time it would take after getting the input, processing it and return the output (hit a key). So, may be on your system, this code will not work properly.
The other case is, due to some variations in device resolution and pixel sizes of different devices, the data for the coordinates of square region may vary on different devices. So, there are a lot of chances that *this code is not for Copy paste coders*
Well, I think I am talking too complicated. This blog is feeling like a professional coder. Isn't it? So, that's all for this project.
If you want more like this, do let me know in the comments below... And Subscribe to this blog because I would be sharing more such projects of mine in future on this blog. Also, if you didn't see, check out my last project of a Music Player web app made in JavaScript.
Click here
Then Bye Bye!
Thanks for reading... :)
See you! (If you subscribe)