# Introduction

Nice to meet you. It will be first post. Both the text and the deliverables will be childish, but I hope you can see them with warm eyes.

# Motivation

In modern baseball, indicators are becoming more common. I made such a calculator because I thought that if I could calculate the index myself, I would be able to enjoy watching baseball, which is my hobby.

# Production procedure

First, create a window.

#### `window`

``````
# coding-utf:8
import tkinter as tk

#Make a window
root = tk.Tk()
root.geometry("400x300")
root.title("Batting performance calculator")

#Run
root.mainloop()
``````

Next, make a label.

#### `label`

``````
#label
labell = tk.Label(root, text="Number of at-bats",font=("Helvetica", 12))
labell.place(x = 20, y = 20)
label2 = tk.Label(root, text="Single hit",font=("Helvetica", 12))
label2.place(x = 20, y = 70)
label3 = tk.Label(root, text="double",font=("Helvetica", 12))
label3.place(x = 20, y = 120)
label4 = tk.Label(root, text="Triple",font=("Helvetica", 12))
label4.place(x = 20, y = 170)
label5 = tk.Label(root, text="Home run",font=("Helvetica", 12))
label5.place(x = 220, y = 20)
label6 = tk.Label(root, text="Four dead balls",font=("Helvetica", 12))
label6.place(x = 220, y = 70)
label7 = tk.Label(root, text="Sacrifice fly",font=("Helvetica", 12))
label7.place(x = 220, y = 120)
``````

Make a text box.

#### `editbox`

``````
#Text box
editbox1 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox1.place(x = 90, y = 20)
editbox2 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox2.place(x = 90, y = 70)
editbox3 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox3.place(x = 90, y = 120)
editbox4 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox4.place(x = 90, y = 170)
editbox5 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox5.place(x = 310, y = 20)
editbox6 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox6.place(x = 310, y = 70)
editbox7 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox7.place(x = 310, y = 120)
``````

Create a button and set the process so that the message is displayed.

#### `button`

``````
import tkinter.messagebox as tsmg

#What to do when the button is clicked
def ButtonClick():
a = editbox1.get()
b = editbox2.get()
c = editbox3.get()
d = editbox4.get()
e = editbox5.get()
f = editbox6.get()
g = editbox7.get()
tsmg.showinfo("batting average",(int(b) + int(c) + int(d) + int(e))/(int(a) - int(f) - int(g)))
tsmg.showinfo("On-base percentage",(int(b) + int(c) + int(d) + int(e) + int(f))/int(a))
tsmg.showinfo("Slugging percentage",((int(b) + int(c)*2 + int(d)*3 + int(e)*4 )/ (int(a) - int(f) - int(g))))
tsmg.showinfo("ops",((int(b) + int(c) + int(d) + int(e) + int(f))/int(a))+(((int(b) + int(c)*2 + int(d)*3 + int(e)*4 )/ (int(a) - int(f) - int(g)))))

#button
buttan1 = tk.Button(root, text = "Calculation", font=("Helvetica", 26), command=ButtonClick)
buttan1.place(x = 80, y = 220)
``````

Combined and completed.

# code

``````# coding-utf:8
import tkinter as tk
import tkinter.messagebox as tsmg

#What to do when the button is clicked
def ButtonClick():
a = editbox1.get()
b = editbox2.get()
c = editbox3.get()
d = editbox4.get()
e = editbox5.get()
f = editbox6.get()
g = editbox7.get()
tsmg.showinfo("batting average",(int(b) + int(c) + int(d) + int(e))/(int(a) - int(f) - int(g)))
tsmg.showinfo("On-base percentage",(int(b) + int(c) + int(d) + int(e) + int(f))/int(a))
tsmg.showinfo("Slugging percentage",((int(b) + int(c)*2 + int(d)*3 + int(e)*4 )/ (int(a) - int(f) - int(g))))
tsmg.showinfo("ops",((int(b) + int(c) + int(d) + int(e) + int(f))/int(a))+(((int(b) + int(c)*2 + int(d)*3 + int(e)*4 )/ (int(a) - int(f) - int(g)))))

#Make a window
root = tk.Tk()
root.geometry("400x300")
root.title("Batting performance calculator")

#label
labell = tk.Label(root, text="Number of at-bats",font=("Helvetica", 12))
labell.place(x = 20, y = 20)
label2 = tk.Label(root, text="Single hit",font=("Helvetica", 12))
label2.place(x = 20, y = 70)
label3 = tk.Label(root, text="double",font=("Helvetica", 12))
label3.place(x = 20, y = 120)
label4 = tk.Label(root, text="Triple",font=("Helvetica", 12))
label4.place(x = 20, y = 170)
label5 = tk.Label(root, text="Home run",font=("Helvetica", 12))
label5.place(x = 220, y = 20)
label6 = tk.Label(root, text="Four dead balls",font=("Helvetica", 12))
label6.place(x = 220, y = 70)
label7 = tk.Label(root, text="Sacrifice fly",font=("Helvetica", 12))
label7.place(x = 220, y = 120)

#Text box
editbox1 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox1.place(x = 90, y = 20)
editbox2 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox2.place(x = 90, y = 70)
editbox3 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox3.place(x = 90, y = 120)
editbox4 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox4.place(x = 90, y = 170)
editbox5 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox5.place(x = 310, y = 20)
editbox6 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox6.place(x = 310, y = 70)
editbox7 = tk.Entry(width = 6,font=("Helvetica", 12))
editbox7.place(x = 310, y = 120)

#button
buttan1 = tk.Button(root, text = "Calculation", font=("Helvetica", 26), command=ButtonClick)
buttan1.place(x = 80, y = 220)

#Run
root.mainloop()
``````

# State of execution

This is the result of Matt Murton in 2010. If you check NPB official website, you can see that the calculation is correct.

# Reflection

・ The calculated grades cannot be displayed together. You have to press OK many times, which is a hassle.

# Impressions

I programmed from scratch for the first time, and I realized how difficult it was. The one I made this time is neither new nor convenient. With this as the starting line, I would like to make efforts to make better products in the future.

# Supplement

### index

The four types calculated this time are batting average, on-base percentage, slugging percentage, and ops. Batting average: An index showing the rate of hits On-base percentage: An index showing the percentage of on-base percentage Slugging percentage: An indicator of how many bases you got ops: An indicator of overall striking ability Please see here for details. I really wanted to do more calculations, but I gave up because it would be annoying if there were too many message displays.

### Personal reflection

** ・ Work as much as you can with a margin ** This is important. Very important. At first, I was thinking of making a game using Pyxel, but I gave up because I couldn't finish it. In the end, I didn't have enough time to spend on this work and it became simple. I realized the importance of making a plan.

・ Punctuation ,. When,. Which one should I use?

# References and sites

Fumitaka Osawa, the easiest Python introductory class, published by Sotec https://npb.jp/bis/players/53155131.html https://1point02.jp/op/gnav/glossary/gls_index.aspx

Recommended Posts