MrDevKnown

SELECT * FROM world WHERE humanity IS NOT NULL;

  • Home
  • About
  • Contact Us

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

from flask import Flask, app
import flask

app = Flask(__name__)

@app.route("/")
def index():
    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_()



PyQt5 Browser code using QtWebEngine


Full Article

Program to find roots of a quadratic equation in Python.

In this post, you will learn to find the roots of a quadratic equation with python.

The Logic
  • We will ask the user to one by one input all the coefficients of the the quadratic equation.
  • Then we are going to use the quadratic formula, i.e. Sridharacharya formula to find the roots of the equation.
  • Then we will check if both the roots are equal or not
  • If both are unequal, we will print them else, we will print one root.
The Code

a = int(input("Enter the coefficient of x\u00b2: "))
b = int(input("Enter the coefficient of x: "))
c = int(input("Enter the numerical coefficient: "))

eq_p = (-b + (b**2 - 4*a*c)**(1/2)) / 2*a
eq_n = (-b - (b**2 - 4*a*c)**(1/2)) / 2*a

if eq_p != eq_n:
    print("The roots of the quadratic equations are:", eq_p, "and", eq_n)
else:
    print("The root of the quadratic equations is:", eq_p)

The Output


Make your own Python Web Browser:

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_()
Full Article



In this post, you will get the free source code of a simple GUI image editting software, made in Tkinter, Python.

The Code


from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from tkinter.filedialog import askopenfilename, asksaveasfilename
from PIL import Image, ImageTk, ImageFilter, ImageEnhance, ImageOps
import os

# main window
root = Tk()
root.title("PhotoEditor")
root.geometry("640x450")

# color code
color = {
    "background": "#009973",
    "canvas": "#00b386",
}

# functions
def selected():
    global img_path, img
    img_path = filedialog.askopenfilename(initialdir=os.getcwd()) 
    img = Image.open(img_path)
    img.thumbnail((350, 350))
    img1 = ImageTk.PhotoImage(img)
    canvas2.create_image(300, 210, image=img1)
    canvas2.image=img1
    ui_controls()
    root.geometry("640x650")
    selectbtn.place(x=100, y=595)
    savebtn.place(x=280, y=595)
    exitbtn.place(x=460, y=595)


def blur(event):
    global img_path, img1, imgg
    for m in range(0, v1.get()+1):
            img = Image.open(img_path)
            img.thumbnail((350, 350))
            imgg = img.filter(ImageFilter.BoxBlur(m))
            img1 = ImageTk.PhotoImage(imgg) 
            canvas2.create_image(300, 210, image=img1)
            canvas2.image=img1


def brightness(event):
    global img_path, img2, img3
    for m in range(0, v2.get()+1):
            img = Image.open(img_path)
            img.thumbnail((350, 350))
            imgg = ImageEnhance.Brightness(img)
            img2 = imgg.enhance(m)
            img3 = ImageTk.PhotoImage(img2)
            canvas2.create_image(300, 210, image=img3)
            canvas2.image=img3


def contrast(event):
    global img_path, img4, img5
    for m in range(0, v3.get()+1):
            img = Image.open(img_path)
            img.thumbnail((350, 350))
            imgg = ImageEnhance.Contrast(img)
            img4 = imgg.enhance(m)
            img5 = ImageTk.PhotoImage(img4)
            canvas2.create_image(300, 210, image=img5)
            canvas2.image=img5

# All ui
select = False
img1 = None
canvas2 = Canvas(root, width="600", height="420", relief=RIDGE, bg=color["canvas"], bd=0)
canvas2.config(highlightbackground=color["background"])
canvas2.place(x=15, y=15)

v1 = IntVar()
v2 = IntVar()
v3 = IntVar()

style = ttk.Style()
style.configure("TScale", background=color["background"])

def ui_controls():
    blurr = Label(root, text="Blur:", font=("ariel 17 bold"), width=9, anchor='e')
    blurr.configure(bg=color["background"])
    blurr.place(x=170, y=455)
    blur_scale = ttk.Scale(root, from_=0, to=10, variable=v1, orient=HORIZONTAL, style="TScale", command=blur)
    blur_scale.place(x=305, y=460)

    bright = Label(root, text="Brightness:", font=("ariel 17 bold"))
    bright.configure(bg=color["background"])
    bright.place(x=163, y=495)
    bright_scale = ttk.Scale(root, from_=0, to=10, variable=v2, orient=HORIZONTAL, command=brightness)
    bright_scale.place(x=305, y=500)

    contrast = Label(root, text="Contrast:", font=("ariel 17 bold"))
    contrast.configure(bg=color["background"])
    contrast.place(x=190, y=535)
    contrast_scale = ttk.Scale(root, from_=0, to=10, variable=v3, orient=HORIZONTAL, command=contrast) 
    contrast_scale.place(x=305, y=540)

selectbtn = Button(root, text="Select Image", bg="royalblue", fg="white", font=("ariel 15 bold"), relief=GROOVE, command=selected)
selectbtn.place(x=100, y=395)

savebtn = Button(root, text="Save", width=12, bg='royalblue', fg='white', font=('ariel 15 bold'), relief=GROOVE)
savebtn.place(x=280, y=395)

exitbtn = Button(root, text="Exit", width=12, bg='red', fg='white', font=('ariel 15 bold'), relief=GROOVE, command=root.destroy)
exitbtn.place(x=460, y=395)


# menu bar
my_menu = Menu(root)
root.config(menu=my_menu)
root.configure(bg=color["background"])

#file menu
file_menu = Menu(my_menu, tearoff=False)
file_menu.add_command(label="New")
file_menu.add_command(label="Save as")
file_menu.add_command(label="Save")
file_menu.add_command(label="Open", command=selected)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=root.quit)
my_menu.add_cascade(label="File", menu=file_menu)

# __main__
root.mainloop()


This is how the software looks...



PyQt5 is a very powerful python gui development framework. This post shows the complete installation and setup of PyQt5 with qt designer tool.

First you need to install Python for this. ALso, make sure the the path is added to the path vatiables. Then open the Windows terminal, cmd and type pip and press enter. If it shows an error then that means, python is not added to path. If it works, then follow the below steps to install and setup pyqt5.



PyQt5 Installation Setup


$ pip install pyqt5

Type the above code in Windows terminal and press Enter key. Wait for the installation

PyQt5 Tools Setup


$ pip install pyqt5-tools

This code will install PyQt5 tools such as qt designer to make the gui.

Qt Designer path

C:\Users\$Username$\AppData\Local\Programs\Python\Python39\Lib\site-packages\qt5_applications\Qt\bin



Note: Edit the $username$ with your username in the above path.

This is how the qt designer window looks like...
Qt designer mrdevknown tutorial. Setup PyQt5 and install qt designer for python.


So, I think that's it for this post... See you in the next.

When you are working with PyQt5, you are using the default OS style of application. The design looks very simple for apps. So, if you are making a cutom app, you will cuystomise the top bar in few cases to have a better design. So, when you are customising the design, you will see that the window has no longer been movable. Thus, you need to write the logic to make the window movable again.
The default Window app style looks like this

The code for doing this is given below...

PyQt5 draggable window Code

Further Reading













.ui to .py file conversion
Qt designer is a designer for GUI. We can designs in it and then save them as a .ui file. When you are working with PyQt5 for making GUI in python, you have to export the .ui file to a .py file. We can do this by using qt-tools. pyuic5 command is used in Python to do this. Go to the path where the ui is saved and enter the below command.

pyuic5 command to convert .ui to .py


$ pyuic5 xyz.ui -o xyz.py

Note: Edit the xyz.ui with the UI file name and xyz.ui with the python file name you want to give to the design in the above command.


To setup complete PyQt5 with Qt tools and install Qt Designer,
Click here

So, I think that's it for this post... See you in the next.
When you are working with PyQt5, you are using the default OS style of application. The design looks very simple for apps. So, if you are making a cutom app, you will cuystomise the top bar in few cases to have a better design. So, when you are customising the design, you will see that the window has no longer been movable. Thus, you need to write the logic to make the window movable again.
The default Window app style looks like this

The code for doing this is given below...

PyQt5 draggable window Code


class movable(QtWidgets.QWidget):
    def __init__(self):
        super(movable, self).__init__()
    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
            event.accept()
    def mouseMoveEvent(self, event):
        if event.buttons() == QtCore.Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)
            event.accept()

You will have to first make a class like this. Then you have to pass the class as parameter in the main window code. Like this...


class mainWindow(movable, Ui_Form):
    def __init__(self):


Here UI form is the form of the design.

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: ✔
...

Code Link
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.
Make your own Web Browser in Python - Python PyQt5 tutorial - QtWebEngineWidgets


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: ✔
...

Code Link
Newer Posts Older Posts Home

ABOUT ME

Web developer, designer. A self taught programmer. Don't hesitate to come for say a small "hello!"
Shivesh Tiwari

POPULAR POSTS

  • How to make your own Screen Recorder with Python - Python OpenCV Tutorial
  • Pyhton Notification System Complete Project with Code
  • Python IDE + Text Editor
  • Chrome Dino Game Automation in Python
  • How to make a Kali Linux themed Terminal Website Portfolio using React JS
  • Logic Building in Python
  • How to make Windows 11 Website Design | Adding Working App Windows | Dark Mode and other things
  • Complete guide on managing code with Github (Git Tutorial)
  • First React Project - TextUtyls Website
  • Make a Windows 11 themed Website - HTML, CSS Windows 11 design

Categories

  • best javascript project 12
  • code 5
  • dino game 1
  • dislike 1
  • easy python projects 9
  • flask 1
  • free python code 10
  • game 2
  • git 1
  • github 1
  • hack 2
  • hack chrome dino game 1
  • hack game 1
  • html best website 4
  • javascript website 6
  • learn javascript 9
  • learn programming 13
  • learn python 15
  • like 1
  • like dislike system php 1
  • mrdevknown 5
  • music player 1
  • notification 1
  • php 2
  • programming 9
  • project 9
  • pyqt5 4
  • python 16
  • python IDE 2
  • python projects 8
  • React 5
  • react js 6
  • software 5
  • Tkinter 2
  • web app 4
  • website 4
Powered by Blogger
MrDevKnown

Search This Blog

Archive

  • August 20231
  • March 20231
  • December 20221
  • September 20222
  • August 20221
  • June 20221
  • March 20221
  • January 20226
  • December 20211
  • November 20213
  • October 202111
  • September 20213
  • August 20213
Show more Show less
  • Home
  • About
  • Contact Us

Subscribe

Posts
Atom
Posts
All Comments
Atom
All Comments

Subscribe

Posts
Atom
Posts
All Comments
Atom
All Comments

Categories

  • React5
  • Tkinter2
  • best javascript project12
  • code5
  • dino game1
  • dislike1
  • easy python projects9
  • flask1
  • free python code10
  • game2
  • git1
  • github1
  • hack2
  • hack chrome dino game1
  • hack game1
  • html best website4
  • javascript website6
  • learn javascript9
  • learn programming13
  • learn python15
  • like1
  • like dislike system php1
  • mrdevknown5
  • music player1
  • notification1
  • php2
  • programming9
  • project9
  • pyqt54
  • python16
  • python IDE2
  • python projects8
  • react js6
  • software5
  • web app4
  • website4

Translate

Pages

  • Home
  • Privacy Policy

Popular Posts

Music Player web app made in HTML, CSS, Javascript

Music Player web app made in HTML, CSS, Javascript

August 03, 2021
Top must have windows software for a developer

Top must have windows software for a developer

September 17, 2022
Javascript code to display a welcome message after accepting the name of the user using a prompt box

Javascript code to display a welcome message after accepting the name of the user using a prompt box

August 20, 2022

Trending Articles

  • How to make your own Screen Recorder with Python - Python OpenCV Tutorial
  • Pyhton Notification System Complete Project with Code
  • Python IDE + Text Editor
  • Chrome Dino Game Automation in Python

Popular Posts

  • Music Player web app made in HTML, CSS, Javascript
  • How to create a shining / glowing effect around the cursor on mouse hover over a div? Glassmorphism Tutorial
  • Javascript code to display a welcome message after accepting the name of the user using a prompt box

Labels

Distributed By Gooyaabi | Designed by OddThemes