5/100
I have a much better understanding of how to build GUIs in python, and I think I made my process a bit less convoluted. I might spend one more day adding more functionality and more atoms, but I’m ready to move on to start working with python in a more data science based arena.
from tkinter import * import atom # builds the GUI window master = Tk() master.title("Atom Builder") canvas_width = 400 canvas_height = 400 # creates the elements and molecules to be displayed on the canvas hydrogen = atom.Element('Hydrogen', 1, 1, 1, 0, 1) oxygen = atom.Element('Oxygen', 8, 16, 8, 8, 8) carbon = atom.Element("Carbon", 6, 12, 6, 6, 6) water = atom.Molecule('Water', 'Bent', [hydrogen, hydrogen, oxygen]) # builds the window l = Label(master, text="Type in a molecule or element: ") l.pack() e1 = Entry(master) e1.pack() b = Button(master,text="enter") b.pack() b1 = Button(master,text="clear") b1.pack() w = Canvas(master, width=canvas_width, height=canvas_height) w.pack() # information to draw the atoms center_x = 200 center_y = 150 hydrogen_color = '#3377ff' oxygen_color = '#ffccff' # draws a circle def circle(canvas, x, y, r, color): id = canvas.create_oval(x - r, y - r, x + r, y + r, fill=color) return id # draws hydrogen def draw_hydrogen(): circle(w, center_x, center_y, hydrogen.atomic_number * 10, hydrogen_color) # draws oxygen def draw_oxygen(): circle(w, center_x, center_y, oxygen.atomic_number * 10, oxygen_color) # draws water def draw_water(): circle(w, 150, 150, 25, hydrogen_color) circle(w, 250, 150, 25, hydrogen_color) circle(w, 200, 100, 50, oxygen_color) # draws certain element/molecule based on text input def draw(text): if text == 'hydrogen': draw_hydrogen() if text == 'oxygen': draw_oxygen() if text == 'water': draw_water() # gets the information on an element/molecule based on text input def get_text(text): if text == 'hydrogen': return hydrogen elif text == 'oxygen': return oxygen elif text == 'water': return water # displays the molecule/element and accompanying text based on textual input def run(event): set_text = e1.get() w.create_text(100, 325, text="%s" % get_text(set_text).__str__()) draw(set_text) # clears canvas display def delete(event): w.delete('all') e1.delete(0,'end') # creates button events b.bind('<Button-1>',run) b1.bind('<Button-1>',delete) # actually builds the GUI mainloop()













