subPTE.py 2.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
import Tkinter as tk

def atomsubmenu(atom, but):

    sub = tk.Tk()
    sub.title(atom['name'])

    propbutton = tk.Menubutton(sub, width=20, text='Edit properties') 
    edit = tk.Menu(propbutton)               
    propbutton.config(menu=edit)

    distbutton = tk.Menubutton(sub, width=20, text='Edit distribution') 
    editdist = tk.Menu(distbutton)               
    distbutton.config(menu=editdist) 

    def cmdadd():
        if  atom['control']==0:
            atom['control']=1
            but['relief']='sunken'
            addremove['text']='Remove element'
        else:
            atom['control']=0
            but['relief']='raised'
            addremove['text']='Add element'

    addremove = tk.Button(sub, width=16, bg='white', command=cmdadd, text='Add element')
    addremove.pack(side='bottom')

    L1 = tk.Label(sub, text = 'Mass - %f' %atom['mass']).pack()
    L2 = tk.Label(sub, text = 'Z - %d' %atom['Z']).pack()

    def cmdmass():
        submass = tk.Tk()
        submass.title('%s - Mass' %atom['name'])
        def modmass():
            atom['mass'] = float(E1.get())
            submass.destroy()
            sub.destroy()
            atomsubmenu(atom, but)
        E1 = tk.Entry(submass, bd =2, width=20)
        E1.pack()
        B1 = tk.Button(submass, text ='Modify', command=modmass, width=18)
        B1.pack()
        E1.focus_force()
        F1 = tk.Frame(submass, width=300)
        F1.pack()
        submass.mainloop()

    def cmdz():
        subz = tk.Tk()
        subz.title('%s - Z' %atom['name'])
        def modz():
            atom['Z'] = int(E2.get(), 10)
            subz.destroy()
            sub.destroy()
            atomsubmenu(atom, but)
        E2 = tk.Entry(subz, bd =2, width=20)
        E2.pack()
        B2 = tk.Button(subz, text ='Modify', command=modz, width=18)
        B2.pack()
        E2.focus_force()
        subz.mainloop()

    def cmdname():
        subname = tk.Tk()
        subname.title('%s - Name' %atom['name'])
        def modname():
            atom['name'] = E3.get()
            subname.destroy()
            sub.destroy()
            atomsubmenu(atom, but)
        E3 = tk.Entry(subname, bd =2, width=20)
        E3.pack()
        B3 = tk.Button(subname, text ='Modify', command=modname, width=18)
        B3.pack()
        E3.focus_force()
        subname.mainloop()

    def cmddraw():
        print atom['mass']
    def cmdnume():
        print atom['name']
    def cmdspecial():
        print atom['Z']
         
    edit.add_command(label='Mass', command=cmdmass)
    edit.add_command(label='Name', command=cmdname)
    edit.add_command(label='Z', command=cmdz)

    editdist.add_command(label='Drawing',  command=cmddraw)
    editdist.add_command(label='Numerical',  command=cmdnume)
    editdist.add_command(label='Special', command=cmdspecial)

    propbutton.pack()
    propbutton.config(bg='white', bd=4, relief='raised')
    distbutton.pack()
    distbutton.config(bg='white', bd=4, relief='raised')
    sub.mainloop()