# Anime Episode

## Anime Episode Calculator

People with good Time Management could always like to optimize their time effectively. This implies even when you have watched anything entertaining.

Unfortunately watching Anime can sometimes be unorganized of our Time. We get so lost that we don’t even recognize what Time it is. But before starting to watch Anime, we always calculate the time, for instance, 1hr equals 3 episodes. What if the anime has 75 episodes, it becomes difficult to calculate. Obviously easy peasy with a calculator.

Here is How you can create an Anime Episodes Calculator.

## Python Tkinter

Now again this is pointless when we know we can’t control our hype and binge entire Anime overnight. But keeping that issue aside, time to focus on Python Tkinter. Python Tkinter allows you to create amazing GUI applications that make your life simpler. With its easy navigation widgets, you can make a GUI application in a few steps. Just like this one. A simple project with simple code.

Basically, an average Anime episode runs for 23 to 25 minutes. That includes opening and ending. A good opening is never to be skipped. Opening, Ending, Precap and Plot carry out an Anime Episode smoothly. Considering the average time to be 23.5 min you can calculate the total time based on the entered episode number.

How will you enter the Episode number? Here you will consider EntryBox, which accepts the user input and on button trigger, you can display the Total Time using the Label widget.

``````import tkinter as tk
from PIL import Image,ImageTk
from tkinter import messagebox

def calculate():
total_episode = entry.get()
if total_episode.isalpha() or len(total_episode)==0 or int(total_episode)<0:
messagebox.showerror("Invalid","Enter Valid Num")
entry.delete(0,"end")
if total_episode.isdigit():
total_time = 23.5*int(total_episode)
if total_time>60:
change = total_time//60
rem = total_time%60
time_req.config(text="{}hr {}min".format(int(change),int(rem)))
else:
time_req.config(text="{}min".format(total_time))

def main():
root = tk.Tk()
root.geometry("475x445+450+200")
root.resizable(False,False)

root.title("Anime Episode Calculator")
img = Image.open('bg.png')
img = img.resize((475,450), Image.ANTIALIAS)
bg= ImageTk.PhotoImage(img)
canvas= tk.Canvas(root)
canvas.pack(expand=True, fill= "both")
canvas.create_image(0,0,image=bg,anchor="nw")

global time_req,entry

entry = tk.Entry(bd=5)
entry.place(x=320,y=100,width=100,height=50)
entry.focus_set()

episode  = tk.Label(text="Enter Total Episode",font=("arial",17,"bold"),bg="white").place(x=30,y=100)
time = tk.Label(text="Total Time Required",font=("arial",17,"bold"),bg="white").place(x=30,y=200)
time_req = tk.Label(text=0,font=("arial",15,"bold"),bg="grey")
time_req.place(x=320,y=200)

btn = tk.Button(text="Calculate",command=calculate,bd=5,bg="black",fg="white").place(x=200,y=370)

root.mainloop()

if __name__ == '__main__':
main()``````

## How To Add Background Image In Tkinter

Adding a background image to the GUI application makes it look attractive. You can do this with help of Tkinter Canvas widget. Python provides Image Library: PIL, with help of this module you can open the image by providing the file path. Once the image is opened, you can resize the image according to the GUI window. This can be done using ImageTk method. And Finally insert the image on GUI application using canva.

``````import tkinter as tk
from PIL import Image,ImageTk

img = Image.open('bg.png')
img = img.resize((475,450), Image.ANTIALIAS)
bg= ImageTk.PhotoImage(img)
canvas= tk.Canvas(root)
canvas.pack(expand=True, fill= "both")
canvas.create_image(0,0,image=bg,anchor="nw")``````

## Tkinter Messagebox

In addition, Tkinter also provides Messagebox. Messagebox acts as an alert window based on the situation. Say if a user is asked to enter a name, but leaves it empty and proceeds further. Using Tkinter messagebox you can prompt show error method. Similarly, you can even use showinfo to prompt information. And also ask yes or no questions using messagebox. Here is the syntax to use Tkinter Messagebox, which takes two string parameters.

``````from tkinter import messagebox