――Recently, I often find out what I thought or thought about (because I have free time). .. .. ――I tried to find out about the zodiac. → ** Zodiac personality diagnosis ** Discovery ――It was unexpectedly hit. (I felt like I was grasping the features well) ――I thought that if you know the zodiac, you can build good relationships, and when you investigate further, you can find an easy way to find it, so I tried programming. [1]
This time I created a program using tkinter
[2]
# coding:utf-8
import tkinter as tk
In creating a program that automatically calculates, I created a basic window I set the size to 300 in width and 250 in height, and set the title to the name to check the zodiac from the Christian era.
root = tk.Tk()
root.geometry("300x250")
root.title("Let's check the zodiac from the Christian era")
Input fields are arranged using ʻEntry, and buttons are arranged using
Button`.
editbox = tk.Entry(width=5, font=("Times", 28))
editbox.place(x = 10, y = 50)
Button = tk.Button(root, text = "button", font=("Helvetica", 12), command=Push)
Button.place(x = 130, y = 60)
I placed a text field to display the zodiac with Text
this time. The width of the text field is 80, and the height is 250.
eto = tk.Text(root, font=("Times", 12))
eto.place(x = 220, y = 0, width=80, height= 250)
First, make a list named ʻEto, The operation (program) that calculates the zodiac from the list when the button is pressed and displays the result in the text field is defined in the function ** Push ** with
def`.
Eto = ["Child", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Not yet", "Monkey", "Rooster", "Dog", "亥"]
def Push():
n = editbox.get()
amari = ((int(n)+9)%12)
global Eto
if amari == 1:
c = Eto[0]
elif amari == 2:
c = Eto[1]
elif amari == 3:
c = Eto[2]
elif amari == 4:
c = Eto[3]
elif amari == 5:
c = Eto[4]
elif amari == 6:
c = Eto[5]
elif amari == 7:
c = Eto[6]
elif amari == 8:
c = Eto[7]
elif amari == 9:
c = Eto[8]
elif amari == 10:
c = Eto[9]
elif amari == 11:
c = Eto[10]
else:
c = Eto[11]
eto.insert(tk.END, str(c) + "\n")
# coding:utf-8
import tkinter as tk
Eto = ["Child", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Not yet", "Monkey", "Rooster", "Dog", "亥"]
def Push():
n = editbox.get()
amari = ((int(n)+9)%12)
global Eto
if amari == 1:
c = Eto[0]
elif amari == 2:
c = Eto[1]
elif amari == 3:
c = Eto[2]
elif amari == 4:
c = Eto[3]
elif amari == 5:
c = Eto[4]
elif amari == 6:
c = Eto[5]
elif amari == 7:
c = Eto[6]
elif amari == 8:
c = Eto[7]
elif amari == 9:
c = Eto[8]
elif amari == 10:
c = Eto[9]
elif amari == 11:
c = Eto[10]
else:
c = Eto[11]
eto.insert(tk.END, str(c) + "\n")
root = tk.Tk()
root.geometry("300x250")
root.title("Let's check the zodiac from the Christian era")
editbox = tk.Entry(width=5, font=("Times", 28))
editbox.place(x = 10, y = 50)
Button = tk.Button(root, text = "button", font=("Helvetica", 12), command=Push)
Button.place(x = 130, y = 60)
eto = tk.Text(root, font=("Times", 12))
eto.place(x = 220, y = 0, width=80, height= 250)
root.mainloop()
--Use a font that suits you best
--The contents of the Push function
seems to be a little easier, so think a little more.
―― Why do you need the str function
to display the ʻEto list` when it should be a character?
[1]. "11 useful calculations to know" [2]. "The easiest Python introductory class", written by Fumitaka Osawa, published by Sotec Co., Ltd.
Recommended Posts