What Is Python - 0
What Is Python - 0
python
Python is a computer programming language often used to build
websites and software, automate tasks, and conduct data analysis.
Python is a general-purpose language, meaning it can be used to
create a variety of different programs and isn't specialized for any
specific problems
or
Python is a high-level, interpreted, general-purpose programming
language. Its design philosophy emphasizes code readability with
the use of significant indentation. Python is dynamically-typed and
garbage
What is Programming
Language
As we know, to communicate with a person, we need a
specific language, similarly to communicate with
computers, programmers also need a language is called
Programming language. Before learning the
programming language, let's understand what is
language
What is Language
Programming
System Software Application software Language
Software
Programming language
software
X=1 Number(int)
y=1.2 Float
Z=1j Complex
P=‘ahmad’ String
Print(type(x))
Print(type(y))
Print(type(z))
What is Variable
keyboard=‘4000’
Computer=‘3000’
Print(int(keyboard)+int(Computer))
Error type
Syntax Error
Runtime error
Syntax Error
Syntax error is a grammerical error in python
print 123
print(123)
Runtime Error
A runtime error in a program is an error that occurs while
the program is running after being successfully compiled
open(‘flower.jpg’)
Input from keyboard or user
name=input(“Enter your name:”)
X=int(input(Enter first Number:”))
Print(“your name is:”)
y=int(input(Enter second Number:”))
Print(name)
Total=x+y
---------------------------------------------
Print(total)
name=input(“Enter your name:”)
Print(f“your name is {name}”)
window=Tk()
Creating lable and
window.title("hi and Hello")
window.geometry('500x300')
Text BOX
lable1=Label(window,text='Enter Your Name:',fg='blue',font=('Arial',14))
lable1.grid(row=0,column=0,padx=5,pady=10)
textbox1=Entry(window,fg='blue',font=('Arial',14))
textbox1.grid(row=0,column=1)
window.mainloop()
from tkinter import *
root Tk()
root.title('your title')
root.geometry("400x400")
Creating Combo
options= [
"sunday"
Box
]
cliked=StringVar()
clicked.set(options[0])
drop = OptionMenu(root, clicked ,*options)
drop.pack(pady=20)
root.mainloop()
Creating
Import tkinter
from tkinter import *
window=Tk()
window.title("hi and Hello")
window.geometry('500x300’)
Radio
r1_1=tkinter.StringVar()
Buttons
r1_1.set(None)
r1=tkinter.Radiobutton(window,text=‘Male’,variable=r1_1,value=‘Male’)
r1.grid(row=1,column=1,padx=50,pady=50)
r2=tkinter.Radiobutton(window,text=‘Female’,variable=r1_1,value=‘Female’)
r2.grid(row=1,column=2)
window.mainloop()
import tkinter as tk
from tkinter.ttk import *
root = tk.Tk()
Creating
root.geometry('100x100')
Buttons
btn = Button(root, text='Click me!', command=root.destroy)
btn.pack(side='top')
root.mainloop()
from tkinter import *
root = Tk()
frame = Frame(root)
Creating
frame.pack()
bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )
redbutton = Button(frame, text = 'Red', fg ='red')
redbutton.pack( side = LEFT) Buttons
greenbutton = Button(frame, text = 'Brown', fg='brown')
greenbutton.pack( side = LEFT )
bluebutton = Button(frame, text ='Blue', fg ='blue')
bluebutton.pack( side = LEFT )
blackbutton = Button(bottomframe, text ='Black', fg ='black')
blackbutton.pack( side = BOTTOM)
root.mainloop()
import tkinter as tk
root = tk.Tk()
Creating
root.title("List Box Example")
root.geometry('1000x1000')
List box
items = ["Apple", "Banana", "Cherry", "Orange", "Grapes"]
listbox = tk.Listbox(root, selectmode=tk.SINGLE)
for item in items:
listbox.insert(tk.END, item)
listbox.pack()
root.mainloop()
import tkinter as tk
Creating
root = tk.Tk()
root.geometry(“900x900”)
Check box
root.title("Checkbox Example")
checkbox_var = tk.IntVar()
checkbox = tk.Checkbutton(root, text="Check me", variable=checkbox_var)
checkbox.pack()
root.mainloop()
from tkinter import *
root = Tk() Creating
menu = Menu(root)
root.config(menu=menu) Menu in
Python
filemenu = Menu(menu)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='New')
filemenu.add_command(label='Open...')
filemenu.add_separator()
filemenu.add_command(label='Exit', command=root.quit)
helpmenu = Menu(menu)
menu.add_cascade(label='Help', menu=helpmenu)
helpmenu.add_command(label='About')
mainloop()
from tkinter import * Creating
master = Tk()
w = Scale(master, from_=0, to=42) Scroll Bar in
w.pack()
w = Scale(master, from_=0, to=200, orient=HORIZONTAL)
w.pack()
Python
mainloop()
from tkinter import *
master = Tk()
Creating
master.geometry('1000x1000')
w = Canvas(master, width=4000, height=6000)
Line
w.pack()
canvas_height=20
canvas_width=2000
y = int(canvas_height / 2)
w.create_line(0, y, canvas_width, y )
mainloop()
import cv2
Importing
img = cv2.imread("sheep.png", cv2.IMREAD_ANYCOLOR)
picture in
while True: python
cv2.imshow("Sheep", img)
key = cv2.waitKey(0)
if key == 27:
break
cv2.destroyAllWindows()
What is Module
A Python module is a file containing Python
definitions and statements. A module can define
functions, classes, and variables. A module can
also include runnable code. Grouping related code
into a module makes the code easier to
understand and use. It also makes the code
logically organized
7
8
9
13
14