Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
8.3 kB
1
Indexable
Never
from tkinter import ttk
from tkinter import *

root = Tk()

root.title("Potomet Kimia")
root.geometry("700x200")

opening = Label(root, text="Halo, selamat datang di potomet kimia, silahkan memasukan keterangan berikut \n", justify="left")
opening.grid(row=0, column=0, columnspan=20)

# senyawa 1
    # koefisien
k1 = Label(root, text="koefisien")
k1.grid(column=1, row=1)

firstclick_k1 = True

def gray_k1(event):
    global firstclick_k1

    if firstclick_k1:
        firstclick_k1 = False
        input_k1.delete(0, "end")

input_k1 = Entry(root, bd=1, width=4, justify="center")
input_k1.insert(0, '...')
input_k1.bind('<FocusIn>', gray_k1)
input_k1.grid(column=1, row=2)

    # senyawa
s1 = Label(root, text="senyawa 1")
s1.grid(column=2, row=1)

firstclick_s1 = True

def gray_s1(event):
    global firstclick_s1

    if firstclick_s1:
        firstclick_s1 = False
        input_s1.delete(0, "end")

input_s1 = Entry(root, bd=1, width=10, justify="center")
input_s1.insert(0, "senyawa 1")
input_s1.bind('<FocusIn>', gray_s1)
input_s1.grid(column=2, row=2)

    #mol
firstclick_n1 = True

def gray_n1(event):
    global firstclick_n1

    if firstclick_n1:
        firstclick_n1 = False
        input_n1.delete(0, "end")

input_n1 = Entry(root, bd=1, width=15, justify="center")
input_n1.insert(0, 'mol senyawa')
input_n1.bind('<FocusIn>', gray_n1)
input_n1.grid(column=1, row=3, columnspan=2)

# +
tambah = Label(root, text="    +    ", bg="grey", height=1, width=1, font=("calibri", 20))
tambah.grid(row=1, column=3, rowspan=2, padx=10)

# senyawa 2
    # koefisien
k2 = Label(root, text="koefisien")
k2.grid(column=4, row=1)

firstclick_k2 = True

def gray_k2(event):
    global firstclick_k2

    if firstclick_k2:
        firstclick_k2 = False
        input_k2.delete(0, "end")

input_k2 = Entry(root, bd=1, width=4, justify="center")
input_k2.insert(0, '...')
input_k2.bind('<FocusIn>', gray_k2)
input_k2.grid(column=4, row=2)

    # senyawa
s2 = Label(root, text="senyawa 2")
s2.grid(column=5, row=1)

firstclick_s2 = True

def gray_s2(event):
    global firstclick_s2

    if firstclick_s2:
        firstclick_s2 = False
        input_s2.delete(0, "end")

input_s2 = Entry(root, bd=1, width=10, justify="center")
input_s2.insert(0, "senyawa 2")
input_s2.bind('<FocusIn>', gray_s2)
input_s2.grid(column=5, row=2)

    #mol2
firstclick_n2 = True

def gray_n2(event):
    global firstclick_n2

    if firstclick_n2:
        firstclick_n2 = False
        input_n2.delete(0, "end")

input_n2 = Entry(root, bd=1, width=15, justify="center")
input_n2.insert(0, 'mol senyawa')
input_n2.bind('<FocusIn>', gray_n2)
input_n2.grid(column=4, row=3, columnspan=2)

# ->
tambah = Label(root, text="    →    ", bg="red", height=1, width=2, font=("calibri", 20))
tambah.grid(column=6, row=1, rowspan=2, padx=10)

#hasil
# senyawa 1
    # koefisien
j1 = Label(root, text="koefisien")
j1.grid(column=7, row=1)

firstclick_j1 = True

def gray_j1(event):
    global firstclick_j1

    if firstclick_j1:
        firstclick_j1 = False
        input_j1.delete(0, "end")

input_j1 = Entry(root, bd=1, width=4, justify="center")
input_j1.insert(0, '...')
input_j1.bind('<FocusIn>', gray_j1)
input_j1.grid(column=7, row=2)

    # senyawa
h1 = Label(root, text="hasil 1", justify="center")
h1.grid(column=8, row=1)

firstclick_h1 = True

def gray_h1(event):
    global firstclick_h1

    if firstclick_h1:
        firstclick_h1 = False
        input_h1.delete(0, "end")

input_h1 = Entry(root, bd=1, width=10, justify="center")
input_h1.insert(0, "hasil 1")
input_h1.bind('<FocusIn>', gray_h1)
input_h1.grid(column=8, row=2)

# +
tambah = Label(root, text="    +    ", bg="grey", height=1, width=1, font=("calibri", 20))
tambah.grid(column=9, row=1, rowspan=2, padx=10)

# senyawa 2
    # koefisien
j2 = Label(root, text="koefisien")
j2.grid(column=10, row=1)

firstclick_j2 = True

def gray_j2(event):
    global firstclick_j2

    if firstclick_j2:
        firstclick_j2 = False
        input_j2.delete(0, "end")

input_j2 = Entry(root, bd=1, width=4, justify="center")
input_j2.insert(0, '...')
input_j2.bind('<FocusIn>', gray_j2)
input_j2.grid(column=10, row=2)

    # senyawa
h2 = Label(root, text="hasil 2")
h2.grid(column=11, row=1)

firstclick_h2 = True

def gray_h2(event):
    global firstclick_h2

    if firstclick_h2:
        firstclick_h2 = False
        input_h2.delete(0, "end")

input_h2 = Entry(root, bd=1, width=10, justify="center")
input_h2.insert(0, "hasil 2")
input_h2.bind('<FocusIn>', gray_h2)
input_h2.grid(column=11, row=2)




#m r s
m = Label(root, text="m", bg="red", width=2)
m.grid(column=0, row=3)

r = Label(root, text="r", bg="yellow", width=2)
r.grid(column=0, row=4)

s = Label(root, text="s", bg="light blue", width=2)
s.grid(column=0, row=5)

#reaksi place
input_r1 = Entry(root , bd=1, width=15, justify="center")
input_r1.grid(column=1, row=4, columnspan=2)

input_r2 = Entry(root , bd=1, width=15, justify="center")
input_r2.grid(column=4, row=4, columnspan=2)

input_t1 = Entry(root , bd=1, width=15, justify="center")
input_t1.grid(column=7, row=4, columnspan=2)

input_t2 = Entry(root , bd=1, width=15, justify="center")
input_t2.grid(column=10, row=4, columnspan=2)

#sisa place
input_u1 = Entry(root , bd=1, width=15, justify="center")
input_u1.grid(column=1, row=5, columnspan=2)

input_u2 = Entry(root , bd=1, width=15, justify="center")
input_u2.grid(column=4, row=5, columnspan=2)

input_p1 = Entry(root , bd=1, width=15, justify="center")
input_p1.grid(column=7, row=5, columnspan=2)

input_p2 = Entry(root , bd=1, width=15, justify="center")
input_p2.grid(column=10, row=5, columnspan=2)

#itung2an bismillah gak pusing
def bereaksi():
    count_k1 = input_k1.get()
    count_n1 = input_n1.get()
    count_k2 = input_k2.get()
    count_n2 = input_n2.get()
    count_j1 = input_j1.get()
    count_j2 = input_j2.get()

    #senyawa 1 habis
    if float(count_n1)/float(count_k1) < float(count_n2)/float(count_k2):
        #reaktan
        reaction_n1 = count_n1
        sisa_n1 = 0

        input_r1.insert(0, str(reaction_n1))
        input_u1.insert(0, str(sisa_n1))

        reaction_n2 = (float(count_n1)*float(count_k2))/float(count_k1)
        sisa_n2 = float(count_n2) - float(reaction_n2)

        input_r2.insert(0, str(reaction_n2))
        input_u2.insert(0, str(sisa_n2))

        #produk
        reaction_t1 = (float(count_n1)*float(count_j1))/float(count_k1)
        reaction_t2 = (float(count_n1)*float(count_j2))/float(count_k1)

        input_t1.insert(0, str(reaction_t1))
        input_p1.insert(0, str(reaction_t1))

        input_t2.insert(0, str(reaction_t2))
        input_p2.insert(0, str(reaction_t2))

    #senyawa 2 habis
    if float(count_n2)/float(count_k2) < float(count_n1)/float(count_k1):
        #reaktan
        reaction_n2 = count_n2
        sisa_n2 = 0

        input_r2.insert(0, str(reaction_n2))
        input_u2.insert(0, str(sisa_n2))

        reaction_n1 = (float(count_n2)*float(count_k1))/float(count_k2)
        sisa_n1 = float(count_n1) - float(reaction_n1)

        input_r1.insert(0, str(reaction_n1))
        input_u1.insert(0, str(sisa_n1))

        #produk
        reaction_t1 = (float(count_n2)*float(count_j1))/float(count_k2)
        reaction_t2 = (float(count_n2)*float(count_j2))/float(count_k2)

        input_t1.insert(0, str(reaction_t1))
        input_p1.insert(0, str(reaction_t1))

        input_t2.insert(0, str(reaction_t2))
        input_p2.insert(0, str(reaction_t2))




#tombol
reaksi = Button(root, text="reaksikan", height=4, width=8, relief="groove", command=bereaksi)
reaksi.grid(column=12, row=1, rowspan=2, padx=10)



#clear
def hapus():
    input_k1.delete(0, END)
    input_s1.delete(0, END)
    input_n1.delete(0, END)
    input_k2.delete(0, END)
    input_s2.delete(0, END)
    input_n2.delete(0, END)
    input_j1.delete(0, END)
    input_h1.delete(0, END)
    input_j2.delete(0, END)
    input_h2.delete(0, END)
    input_r1.delete(0, END)
    input_r2.delete(0, END)
    input_t1.delete(0, END)
    input_t2.delete(0, END)
    input_u1.delete(0, END)
    input_u2.delete(0, END)
    input_p1.delete(0, END)
    input_p2.delete(0, END)

clear = Button(root, text="clear", height=4, width=8, command=hapus, relief="groove")
clear.grid(column=12, row=3, rowspan=4)

root.mainloop()