dropdown menu

Back To Home

Saturday, April 11, 2020

No module named PIL solved

No module named PIL solved.
At command propmpt: pip install pillow
 

Install free python IDE for window

Here is the step to install free python IDE for window.


No module named cv2 solved

No module named cv2 solved.

At command prompt type: pip install opencv-python.



Saturday, March 21, 2020

python-resize image

we can resize image using cv2 module.

Python code:
import cv2

img = cv2.imread('/home/pi/Desktop/download.jpeg') #read the image
width = int(1280 * 0.5) #width to resize
height = int(720 * 0.5) #height to resize
dim = (width, height)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)  #using API of cv2 resize
cv2.imwrite('/home/pi/Desktop/download_resize.jpg',resized)  #then use cv2 to write out image

original image:


resized image:


Friday, January 3, 2020

Python tkinter - video preview in label

Video preview by using python tkinter.

Python code:

from tkinter import *
from PIL import ImageTk, Image
import cv2

root2=Tk()
root2.title('Video preview')


#Layout of display
topFrame =Frame(root2,width=100,height=100)
topFrame.grid(rowspan=2)



#topFrame
lmain = Label(topFrame,width=600,height=500)
lmain.grid()

cap=cv2.VideoCapture(0)


def video_stream():


    _, frame = cap.read()
  

   
    cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
    img = Image.fromarray(cv2image)
    imgtk = ImageTk.PhotoImage(image=img)
    lmain.imgtk = imgtk
    lmain.configure(image=imgtk)
    lmain.after(1, video_stream)


video_stream()

   
root2.mainloop()




Friday, December 20, 2019

python tkinter-update label while program running (progress bar from 0% to 100%)

python tkinter update label while program running (progress bar from 0% to 100%)
Update continuously even you have button and button is clicked.
Just put config text and root.update() inside function def.

The progress bar:


Program:

from tkinter import *
import time

root=Tk()

a=Label(root,fg="blue")
a.pack()

a.config(text="processing 10%")
root.update()
time.sleep(1)
#program
a.config(text="processing 30%")
root.update()
time.sleep(1)
#program
a.config(text="processing 60%")
root.update()
time.sleep(1)
#program
a.config(text="processing 100%")
root.update()
time.sleep(1)

root.mainloop()



Python tkinter update label progress bar while button is clicked.

The progress bar(with button):


Program:
from tkinter import *
import time

root=Tk()

a=Label(root,fg="blue")
a.pack()

def run():
 a.config(text="processing 10%")
 root.update()
 time.sleep(1)
 #program
 a.config(text="processing 30%")
 root.update()
 time.sleep(1)
 #program
 a.config(text="processing 60%")
 root.update()
 time.sleep(1)
 #program
 a.config(text="processing 100%")
 root.update()
 time.sleep(1)

b=Button(root,text="run",command=run)
b.pack()



root.mainloop()

                  

Sunday, December 8, 2019

Python tkinter- Screen1 appear on top or bottom screen 2

Python code:

Page1.py:

import tkinter as tk
import os

root = tk.Tk()
root.attributes('-type', 'dock')
root.title('top')
#root.attributes('-type', 'splash')
root.geometry('200x200+100+100')

def open():
  os.system('python3 top2')
  
a=tk.Button(root,text="open screen 2",command=open)
a.pack()

root.mainloop()

Page2.py:

import tkinter as tk

root = tk.Tk()

root.title('top2')

root.geometry('200x200+150+150')
root.mainloop()


Screen 2 appear on top screen 1(dock):




Screen 2 appear on bottom screen 1(splash):

Video: