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



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 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
  • How to make Windows 11 Website Design | Adding Working App Windows | Dark Mode and other things
  • How to test your typing speed with Python - Make a Python app
  • Make a Windows 11 themed Website - HTML, CSS Windows 11 design
  • Top must have windows software for a developer
  • Qt Designer UI to python file export
  • Python PyQt5 complete Setup Windows
  • PyQt5 draggable Custom window code
  • Make your own Python IDE + Text Editor (Pykachu)

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 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
  • How to make Windows 11 Website Design | Adding Working App Windows | Dark Mode and other things
  • How to test your typing speed with Python - Make a Python app

Popular Posts

  • Top must have windows software for a developer
  • Javascript code to display a welcome message after accepting the name of the user using a prompt box
  • How to create a shining / glowing effect around the cursor on mouse hover over a div? Glassmorphism Tutorial

Labels

Distributed By Gooyaabi | Designed by OddThemes