Skip to content

Commit

Permalink
Merge pull request #9 from aloner-pro/main
Browse files Browse the repository at this point in the history
Added Periodic Table
  • Loading branch information
shreyamalogi authored Oct 24, 2023
2 parents 6e2adc3 + 7de1f25 commit 6821bc9
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Turtle-a-thon/Periodic Table/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# Periodic Table

Periodic Table GUI made using python & tkinter.
For more information look [here](https://github.com/aloner-pro/Chemistry-tools).

![GitHub](https://img.shields.io/github/license/aloner-pro/Chemistry-tools)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/aloner-pro/Chemistry-tools)

## How does it look

![Periodic](https://github.com/aloner-pro/Chemistry-tools/blob/master/new.png?raw=true)

## Features

- Easy to use
- Hovering effect
- Fullscreen mode
- Cross platform

## Run Locally

Clone the project

```bash
git clone https://github.com/aloner-pro/Chemistry-tools.git
```

Go to the project directory

```bash
cd Chemistry-tools
```

Good to go just you need to have python.

## Lessons Learned

Learnt a lot about tkinter and various of it's widgets. It made me a proper googler.
Moreover got to apply & learn a lot more of the fundamentals of python.

## License

[MIT](https://choosealicense.com/licenses/mit/)
119 changes: 119 additions & 0 deletions Turtle-a-thon/Periodic Table/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
Symbol,Element,AtomicNumber,AtomicMass,Period,Group,Phase,Type
H,Hydrogen,1,1.007,1,1,gas,Nonmetal
He,Helium,2,4.002,1,18,gas,Noble Gas
Li,Lithium,3,6.941,2,1,solid,Alkali Metal
Be,Beryllium,4,9.012,2,2,solid,Alkaline Earth Metal
B,Boron,5,10.811,2,13,solid,Metalloid
C,Carbon,6,12.011,2,14,solid,Nonmetal
N,Nitrogen,7,14.007,2,15,gas,Nonmetal
O,Oxygen,8,15.999,2,16,gas,Nonmetal
F,Fluorine,9,18.998,2,17,gas,Halogen
Ne,Neon,10,20.18,2,18,gas,Noble Gas
Na,Sodium,11,22.99,3,1,solid,Alkali Metal
Mg,Magnesium,12,24.305,3,2,solid,Alkaline Earth Metal
Al,Aluminum,13,26.982,3,13,solid,Metal
Si,Silicon,14,28.086,3,14,solid,Metalloid
P,Phosphorus,15,30.974,3,15,solid,Nonmetal
S,Sulfur,16,32.065,3,16,solid,Nonmetal
Cl,Chlorine,17,35.453,3,17,gas,Halogen
Ar,Argon,18,39.948,3,18,gas,Noble Gas
K,Potassium,19,39.098,4,1,solid,Alkali Metal
Ca,Calcium,20,40.078,4,2,solid,Alkaline Earth Metal
Sc,Scandium,21,44.956,4,3,solid,Transition Metal
Ti,Titanium,22,47.867,4,4,solid,Transition Metal
V,Vanadium,23,50.942,4,5,solid,Transition Metal
Cr,Chromium,24,51.996,4,6,solid,Transition Metal
Mn,Manganese,25,54.938,4,7,solid,Transition Metal
Fe,Iron,26,55.845,4,8,solid,Transition Metal
Co,Cobalt,27,58.933,4,9,solid,Transition Metal
Ni,Nickel,28,58.693,4,10,solid,Transition Metal
Cu,Copper,29,63.546,4,11,solid,Transition Metal
Zn,Zinc,30,65.38,4,12,solid,Transition Metal
Ga,Gallium,31,69.723,4,13,solid,Metal
Ge,Germanium,32,72.64,4,14,solid,Metalloid
As,Arsenic,33,74.922,4,15,solid,Metalloid
Se,Selenium,34,78.96,4,16,solid,Nonmetal
Br,Bromine,35,79.904,4,17,liq,Halogen
Kr,Krypton,36,83.798,4,18,gas,Noble Gas
Rb,Rubidium,37,85.468,5,1,solid,Alkali Metal
Sr,Strontium,38,87.62,5,2,solid,Alkaline Earth Metal
Y,Yttrium,39,88.906,5,3,solid,Transition Metal
Zr,Zirconium,40,91.224,5,4,solid,Transition Metal
Nb,Niobium,41,92.906,5,5,solid,Transition Metal
Mo,Molybdenum,42,95.96,5,6,solid,Transition Metal
Tc,Technetium,43,98,5,7,artificial,Transition Metal
Ru,Ruthenium,44,101.07,5,8,solid,Transition Metal
Rh,Rhodium,45,102.906,5,9,solid,Transition Metal
Pd,Palladium,46,106.42,5,10,solid,Transition Metal
Ag,Silver,47,107.868,5,11,solid,Transition Metal
Cd,Cadmium,48,112.411,5,12,solid,Transition Metal
In,Indium,49,114.818,5,13,solid,Metal
Sn,Tin,50,118.71,5,14,solid,Metal
Sb,Antimony,51,121.76,5,15,solid,Metalloid
Te,Tellurium,52,127.6,5,16,solid,Metalloid
I,Iodine,53,126.904,5,17,solid,Halogen
Xe,Xenon,54,131.293,5,18,gas,Noble Gas
Cs,Cesium,55,132.905,6,1,solid,Alkali Metal
Ba,Barium,56,137.327,6,2,solid,Alkaline Earth Metal
La,Lanthanum,57,138.905,6,3,solid,Lanthanide
Ce,Cerium,58,140.116,6,,solid,Lanthanide
Pr,Praseodymium,59,140.908,6,,solid,Lanthanide
Nd,Neodymium,60,144.242,6,,solid,Lanthanide
Pm,Promethium,61,145,6,,artificial,Lanthanide
Sm,Samarium,62,150.36,6,,solid,Lanthanide
Eu,Europium,63,151.964,6,,solid,Lanthanide
Gd,Gadolinium,64,157.25,6,,solid,Lanthanide
Tb,Terbium,65,158.925,6,,solid,Lanthanide
Dy,Dysprosium,66,162.5,6,,solid,Lanthanide
Ho,Holmium,67,164.93,6,,solid,Lanthanide
Er,Erbium,68,167.259,6,,solid,Lanthanide
Tm,Thulium,69,168.934,6,,solid,Lanthanide
Yb,Ytterbium,70,173.054,6,,solid,Lanthanide
Lu,Lutetium,71,174.967,6,,solid,Lanthanide
Hf,Hafnium,72,178.49,6,4,solid,Transition Metal
Ta,Tantalum,73,180.948,6,5,solid,Transition Metal
W,Tungsten,74,183.84,6,6,solid,Transition Metal
Re,Rhenium,75,186.207,6,7,solid,Transition Metal
Os,Osmium,76,190.23,6,8,solid,Transition Metal
Ir,Iridium,77,192.217,6,9,solid,Transition Metal
Pt,Platinum,78,195.084,6,10,solid,Transition Metal
Au,Gold,79,196.967,6,11,solid,Transition Metal
Hg,Mercury,80,200.59,6,12,liq,Transition Metal
Tl,Thallium,81,204.383,6,13,solid,Metal
Pb,Lead,82,207.2,6,14,solid,Metal
Bi,Bismuth,83,208.98,6,15,solid,Metal
Po,Polonium,84,210,6,16,solid,Metalloid
At,Astatine,85,210,6,17,solid,Halogen
Rn,Radon,86,222,6,18,gas,Noble Gas
Fr,Francium,87,223,7,1,solid,Alkaline Metal
Ra,Radium,88,226,7,2,solid,Alkaline Earth Metal
Ac,Actinium,89,227,7,3,solid,Actinide
Th,Thorium,90,232.038,7,,solid,Actinide
Pa,Protactinium,91,231.036,7,,solid,Actinide
U,Uranium,92,238.029,7,,solid,Actinide
Np,Neptunium,93,237,7,,artificial,Actinide
Pu,Plutonium,94,244,7,,artificial,Actinide
Am,Americium,95,243,7,,artificial,Actinide
Cm,Curium,96,247,7,,artificial,Actinide
Bk,Berkelium,97,247,7,,artificial,Actinide
Cf,Californium,98,251,7,,artificial,Actinide
Es,Einsteinium,99,252,7,,artificial,Actinide
Fm,Fermium,100,257,7,,artificial,Actinide
Md,Mendelevium,101,258,7,,artificial,Actinide
No,Nobelium,102,259,7,,artificial,Actinide
Lr,Lawrencium,103,262,7,,artificial,Actinide
Rf,Rutherfordium,104,261,7,4,artificial,Transactinide
Db,Dubnium,105,262,7,5,artificial,Transactinide
Sg,Seaborgium,106,266,7,6,artificial,Transactinide
Bh,Bohrium,107,264,7,7,artificial,Transactinide
Hs,Hassium,108,267,7,8,artificial,Transactinide
Mt,Meitnerium,109,268,7,9,artificial,Transactinide
Ds,Darmstadtium,110,271,7,10,artificial,Transactinide
Rg,Roentgenium,111,272,7,11,artificial,Transactinide
Cn,Copernicium,112,285,7,12,artificial,Transactinide
Nh,Nihonium,113,284,7,13,artificial,
Fl,Flerovium,114,289,7,14,artificial,Transactinide
Mc,Moscovium,115,288,7,15,artificial,
Lv,Livermorium,116,292,7,16,artificial,Transactinide
Ts,Tennessine,117,295,7,17,artificial,
Og,Oganesson,118,294,7,18,artificial,Noble Gas
53 changes: 53 additions & 0 deletions Turtle-a-thon/Periodic Table/hovering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from tkinter import *
"""
This module helps us to have a hovering effect on any
widget in tkinter. It helps in giving the user info about
the widget. Especially used to hover over buttons and giving
info about their usage.
for more info visit link - https://cutt.ly/fhzdiqy
"""


class ToolTip(object):

def __init__(self, widget):
self.widget = widget
self.tip_window = None
self.id = None
self.x = self.y = 0

def showtip(self, text):
"""Display text in tooltip window"""
self.text = text
if self.tip_window or not self.text:
return
x, y, cx, cy = self.widget.bbox("insert")
x = x + self.widget.winfo_rootx() + 57
y = y + cy + self.widget.winfo_rooty() + 27
self.tip_window = tw = Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x, y))
label = Label(tw, text=self.text, justify=LEFT,
background="#ffffe0", relief=SOLID, borderwidth=1,
font=("Berlin Sans FB", "12", "normal"))
label.pack(ipadx=1)

def hidetip(self):
tw = self.tip_window
self.tip_window = None
if tw:
tw.destroy()


def create_tool_tip(widget, text):
"""Main function which is called in programs"""
tool_tip = ToolTip(widget)

def enter(event):
tool_tip.showtip(text)

def leave(event):
tool_tip.hidetip()

widget.bind('<Enter>', enter)
widget.bind('<Leave>', leave)
88 changes: 88 additions & 0 deletions Turtle-a-thon/Periodic Table/periodicTable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Program to display periodic table
import csv
from tkinter import *
import hovering as ho

with open('data.csv', 'r') as d:
td = list(csv.reader(d))
data, lan = [], []
for i in td[1:]:
if i[-3] != '':
data.append(i)
else:
lan.append(i)
g1 = []
for k in range(19):
for j in data:
if int(j[-3]) == k:
g1.append(j)

root = Tk()
root.config(bg='#A5C9BC')
root.title('Periodic Table')

# Centering the window
root_h, root_w = 710, 1200
s_w = root.winfo_screenwidth()
s_h = root.winfo_screenheight()
x_co = int((s_w / 2) - (root_w / 2))
y_co = int((s_h / 2) - (root_h / 2))
root.geometry("{}x{}+{}+{}".format(root_w, root_h, x_co, y_co))


def elements_display(ele_sym: str, ele_name: str, at_no: int, at_mass: float, button_obj):
ho.create_tool_tip(button_obj, f'Element Symbol: {ele_sym}\nElement Name: {ele_name}\nAtomic Number: {at_no}'
f'\nAtomic Mass: {at_mass}')


def ele_7(ele_list, x_, color):
for a in range(7):
du = ele_list[a]
bu_7 = Button(root, text=du[0], height=4, width=8, bg=color, relief='groove', font=('Times New Roman', 10))
bu_7.place(x=x_, y=40 + a * 70)
elements_display(du[0], du[1], du[2], du[3], bu_7)


def ele_6(ele_list, x_, color):
for a in range(6):
du = ele_list[a]
bu_6 = Button(root, text=du[0], height=4, width=8, bg=color, relief='groove', font=('Times New Roman', 10))
bu_6.place(x=x_, y=110 + a * 70)
elements_display(du[0], du[1], du[2], du[3], bu_6)


def ele_4(ele_list, x_):
for a in range(4):
du = ele_list[a]
bu_4 = Button(root, text=du[0], height=4, width=8, bg='#EEE3BC', relief='groove',
font=('Times New Roman', 10))
bu_4.place(x=x_, y=250 + a * 70)
elements_display(du[0], du[1], du[2], du[3], bu_4)


def lan_act(ele, y_):
for t in range(14):
fe = ele[t]
bu_la = Button(root, text=fe[0], height=4, width=8, bg='#8287B4', relief='groove', font=('Times New Roman', 10))
bu_la.place(x=135 + t * 66, y=y_)
elements_display(fe[0], fe[1], fe[2], fe[3], bu_la)


ele_7(g1[:7], 3, '#507F9B')
ele_6(g1[7:13], 69, '#507F9B')

for y in range(10):
ele_4(g1[13 + (4 * y):17 + (4 * y)], 135 + (66 * y))

for z in range(5):
ele_6(g1[53 + (6 * z):59 + (6 * z)], 795 + (66 * z), '#89B6E4')

ele_7(g1[83:90], 1125, '#89B6E4')
lan_act(lan[:14], 545)
lan_act(lan[14:], 615)

exit_bu = Button(root, text='Exit', command=root.destroy, bg='red', fg='yellow', relief='groove',
font=('Times New Roman', 10))
exit_bu.place(x=1100, y=600)
ho.create_tool_tip(exit_bu, "Closes the window")
root.mainloop()

0 comments on commit 6821bc9

Please sign in to comment.