Age Calculator

from tkinter import *

from tkinter import messagebox

def clearAll() :

    dayField.delete(0, END)

    monthField.delete(0, END)

    yearField.delete(0, END)

    givenDayField.delete(0, END)

    givenMonthField.delete(0, END)

    givenYearField.delete(0, END)

    rsltDayField.delete(0, END)

    rsltMonthField.delete(0, END)

    rsltYearField.delete(0, END)

def checkError() :

    if (dayField.get() == "" or monthField.get() == ""

        or yearField.get() == "" or givenDayField.get() == ""

        or givenMonthField.get() == "" or givenYearField.get() == "") :

        messagebox.showerror("Input Error")

        clearAll()

        return -1

def calculateAge() :

    value = checkError()

    if value == -1 :

        return

    else :

        birth_day = int(dayField.get())

        birth_month = int(monthField.get())

        birth_year = int(yearField.get())

        given_day = int(givenDayField.get())

        given_month = int(givenMonthField.get())

        given_year = int(givenYearField.get())

        month =[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

        if (birth_day > given_day):

            given_month = given_month - 1

            given_day = given_day + month[birth_month-1]

        if (birth_month > given_month):

            given_year = given_year - 1

            given_month = given_month + 12

        calculated_day = given_day - birth_day;

        calculated_month = given_month - birth_month;

        calculated_year = given_year - birth_year;

        rsltDayField.insert(10, str(calculated_day))

        rsltMonthField.insert(10, str(calculated_month))

        rsltYearField.insert(10, str(calculated_year))

if __name__ == "__main__" :

    gui = Tk()

    gui.configure(background = "light green")

    gui.title("Age Calculator")

    gui.geometry("525x260")

    dob = Label(gui, text = "Date Of Birth", bg = "light green")

    givenDate = Label(gui, text = "Given Date", bg = "light green")

    day = Label(gui, text = "Day", bg = "light green")

    month = Label(gui, text = "Month", bg = "light green")

    year = Label(gui, text = "Year", bg = "light green")

    givenDay = Label(gui, text = "Given Day", bg = "light green")

    givenMonth = Label(gui, text = "Given Month", bg = "light green")

    givenYear = Label(gui, text = "Given Year", bg = "light green")

    rsltYear = Label(gui, text = "Years", bg = "light green")

    rsltMonth = Label(gui, text = "Months", bg = "light green")

    rsltDay = Label(gui, text = "Days", bg = "light green")

    resultantAge = Button(gui, text = "Resultant Age", fg = "Black", bg = "light blue", command = calculateAge)

    clearAllEntry = Button(gui, text = "Clear All", fg = "Black", bg = "light blue", command = clearAll)

    dayField = Entry(gui)

    monthField = Entry(gui)

    yearField = Entry(gui)

    givenDayField = Entry(gui)

    givenMonthField = Entry(gui)

    givenYearField = Entry(gui)

    rsltYearField = Entry(gui)

    rsltMonthField = Entry(gui)

    rsltDayField = Entry(gui)

    dob.grid(row = 0, column = 1)

    day.grid(row = 1, column = 0)

    dayField.grid(row = 1, column = 1)

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

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

    year.grid(row = 3, column = 0)

    yearField.grid(row = 3, column = 1)

    givenDate.grid(row = 0, column = 4)

    givenDay.grid(row = 1, column = 3)

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

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

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

    givenYear.grid(row = 3, column = 3)

    givenYearField.grid(row = 3, column = 4)

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

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

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

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

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

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

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

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

    gui.mainloop()


TIOBE Index for January 2023

C++ is TIOBE's programming language of the year 2022. It has won this title because C++ gained most popularity (+4.62%) in 2022. Runners up are C (+3.82%) and Python (+2.78%). Interestingly, C++ surpassed Java to become the number 3 of the TIOBE index in  November 2022.

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()