Image Viewer

from tkinter import *

from PIL import ImageTk, Image

def forward(img_no):

    global label

    global button_forward

    global button_back

    global button_exit

    label.grid_forget()

    label = Label(image=List_images[img_no-1])

    label.grid(row=1, column=0, columnspan=3)

    button_for = Button(root, text="forward",

                        command=lambda: forward(img_no+1))

    if img_no == 4:

        button_forward = Button(root, text="Forward",

                                state=DISABLED)

    button_back = Button(root, text="Back",

                        command=lambda: back(img_no-1))

    button_back.grid(row=5, column=0)

    button_exit.grid(row=5, column=1)

    button_for.grid(row=5, column=2)

def back(img_no):

    global label

    global button_forward

    global button_back

    global button_exit

    label.grid_forget()

    label = Label(image=List_images[img_no - 1])

    label.grid(row=1, column=0, columnspan=3)

    button_forward = Button(root, text="forward",

                            command=lambda: forward(img_no + 1))

    button_back = Button(root, text="Back",

                        command=lambda: back(img_no - 1))

    print(img_no)

    if img_no == 1:

        button_back = Button(root, Text="Back", state=DISABLED)

    label.grid(row=1, column=0, columnspan=3)

    button_back.grid(row=5, column=0)

    button_exit.grid(row=5, column=1)

    button_for.grid(row=5, column=2)

root = Tk()

root.title("Image Viewer")

root.geometry("700x700")

image_no_1 = ImageTk.PhotoImage(Image.open("sample.jpg"))

image_no_2 = ImageTk.PhotoImage(Image.open("sample.jpg"))

image_no_3 = ImageTk.PhotoImage(Image.open("sample.jpg"))

image_no_4 = ImageTk.PhotoImage(Image.open("sample.jpg"))

List_images = [image_no_1, image_no_2, image_no_3, image_no_4]

label = Label(image=image_no_1)

label.grid(row=1, column=0, columnspan=3)

button_back = Button(root, text="Back", command=back,

                    state=DISABLED)

button_exit = Button(root, text="Exit",

                    command=root.quit)

button_forward = Button(root, text="Forward",

                        command=lambda: forward(1))

button_back.grid(row=5, column=0)

button_exit.grid(row=5, column=1)

button_forward.grid(row=5, column=2)

root.mainloop()


Voice Recorder

import sounddevice as sd

from scipy.io.wavfile import write

import wavio as wv

freq = 44100

duration = 5

recording = sd.rec(int(duration * freq),

                samplerate=freq, channels=2)

sd.wait()

write("recording0.wav", freq, recording)

wv.write("recording1.wav", recording, freq, sampwidth=2)


Percentage Finder

from tkinter import *

def getPercentage() :

    students= int(total_participantField.get())

    rank = int(rankField.get())

    result = round((students - rank) / students * 100,3);

    percentageField.insert(10, str(result))

def Clear():

    rankField.delete(0, END)

    total_participantField.delete(0, END)

    percentageField.delete(0, END)

if __name__ == "__main__" :

    gui = Tk()

    gui.configure(background = "light pink")

    gui.title("Rank Based- percentage Calculator")

    gui.geometry("650x200")

    rank = Label(gui, text = "Rank", bg = "light green")

    andl = Label(gui, text = "And", bg = "light green")

    total_participant = Label(gui,

                            text = "Total Participants",

                            bg = "light green")

    find = Button(gui, text = "Find percentage",

                fg = "Black", bg = "Red",

                command = getPercentage)

    percentage = Label(gui, text = "percentage", bg = "light green")

    clear = Button(gui, text = "Clear",

                fg = "Black", bg = "Red",

                command = Clear)

    rank.grid(row = 1, column = 1,padx = 10)

    andl.grid(row = 1, column = 4)

    total_participant.grid(row = 1, column = 6, padx = 10)

    find.grid(row = 3, column = 4,pady = 10)

    percentage.grid(row = 4, column = 3,padx = 10)

    clear.grid(row = 5, column = 4,pady = 10)

    rankField = Entry(gui)

    total_participantField = Entry(gui)

    percentageField = Entry(gui)

    rankField.grid(row = 1, column = 2)

    total_participantField.grid(row = 1, column = 7)

    percentageField.grid(row = 4, column = 4)

    

    gui.mainloop()


Tree using python turtle

from turtle import *

speed('fastest')

# turning the turtle to face upwards

rt(-90)

# the base and branch of the Y

angle = 30

# function to plot a Y

def y(sz, level):

    if level > 0:

        colormode(255)

        pencolor(0, 255//level, 0)

        fd(sz)

        rt(angle)

        # recursive call 

        y(0.8 * sz, level-1)

        pencolor(0, 255//level, 0)

        lt( 2 * angle )

        y(0.8 * sz, level-1)

        pencolor(0, 255//level, 0)

        rt(angle)

        fd(-sz)

y(80, 7)


Sentiment Analyzer

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

from tkinter import *

def clear() :

    negativeField.delete(0, END)

    neutralField.delete(0, END)

    positiveField.delete(0, END)

    overallField.delete(0, END)

    textArea.delete(1.0, END)

def detect_sentiment():

    sentence = textArea.get("1.0", "end")

    sid_obj = SentimentIntensityAnalyzer()

    sentiment_dict = sid_obj.polarity_scores(sentence)

    string = str(sentiment_dict['neg']*100) + "% Negative"

    negativeField.insert(10, string)

    string = str(sentiment_dict['neu']*100) + "% Neutral"

    neutralField.insert(10, string)

    string = str(sentiment_dict['pos']*100) +"% Positive"

    positiveField.insert(10, string)

    if sentiment_dict['compound'] >= 0.05 :

        string = "Positive"

    elif sentiment_dict['compound'] <= - 0.05 :

        string = "Negative"

    else :

        string = "Neutral"

    overallField.insert(10, string)

if __name__ == "__main__" :

    gui = Tk()

    gui.config(background = "light blue")

    gui.title("Sentiment Detector")

    gui.geometry("250x400")

    enterText = Label(gui, text = "Enter Your Sentence",

                                    bg = "light blue")

    textArea = Text(gui, height = 5, width = 25, font = "lucida 13")

    check = Button(gui, text = "Check Sentiment", fg = "Black",

                        bg = "Red", command = detect_sentiment)

    negative = Label(gui, text = "sentence was rated as: ",

                                        bg = "light blue")

    neutral = Label(gui, text = "sentence was rated as: ",

                                    bg = "light blue")

    positive = Label(gui, text = "sentence was rated as: ",

                                        bg = "light blue")

    overall = Label(gui, text = "Sentence Overall Rated As: ",

                                        bg = "light blue")

    negativeField = Entry(gui)

    neutralField = Entry(gui)

    positiveField = Entry(gui)

    overallField = Entry(gui)

    clear = Button(gui, text = "Clear", fg = "Black",

                    bg = "Red", command = clear)

    Exit = Button(gui, text = "Exit", fg = "Black",

                        bg = "Red", command = exit)

    enterText.grid(row = 0, column = 2)

    textArea.grid(row = 1, column = 2, padx = 10, sticky = W)

    check.grid(row = 2, column = 2)

    negative.grid(row = 3, column = 2)

    neutral.grid(row = 5, column = 2)

    positive.grid(row = 7, column = 2)

    overall.grid(row = 9, column = 2)

    negativeField.grid(row = 4, column = 2)

    neutralField.grid(row = 6, column = 2)             

    positiveField.grid(row = 8, column = 2)

    overallField.grid(row = 10, column = 2)

    clear.grid(row = 11, column = 2)

    Exit.grid(row = 12, column = 2)

    gui.mainloop()