I've written a neat little scrip in python that allows me to input a heap of data as text which then collates and formats it all into a usable form.
I wrote this to help keep on top of analysis that I do on chemical compounds and am wanting to convert it into a GUI so that other people I work with can use it easily enough.
The 1st problem I'm having is as follows. I want to have an entry field that gets added every time a botton gets clicked. The idea being that if you need to enter more than on bit of information you just click a button and away you go.
I accomplished this in python by having an array that was appended every time somethign looped. like so:
hpeaks = raw_input("How many HNMR peaks do you need to enter? \n") hsolvent = raw_input("What solvent did you use for the HNMR ?: \n") x = int(hpeaks) no = 1 while (x != 0): ppm = raw_input("what is the shift of peak No " + str(no) + " ?:") multip = raw_input("what is the multiplicity of peak No " + str(no) + " ?:") inter = raw_input("what is the intergration of peak No " + str(no) + " ?:") jcoup = raw_input("what is the coupling of peak No " + str(no) + " ?:") shift.append(ppm) mult.append(multip) hs.append(inter) coup.append(jcoup) x = x - 1 no = no + 1
This worked well but I cant see/find a way to do this using tkinter.
This is what I've come up with so far (just trying to get all the bits and pieces to work before I have multiple entry fields to add etc.)
from Tkinter import * root = Tk() def save(): test = shift.get() f = open(test + ".txt", "w") f.write("this is a " + test) def addpeak(): offset = 0 shift = Entry(root, width = 5) shift.pack() shift.place(x = 20, y = 20 + offset) offset = offset + 20 b = Button(root, text="Save", width=10, command=save) add = Button(root, text = "Add peak", width = 10, command = addpeak) b.pack() b.place(x = 100, y = 40) add.pack() add.place(x = 230, y = 40) root.mainloop()
I'm assuming that I'll need to change the "shift" variable everytime the Add Peak button is pressed so that the .get() works correctly but have no idea how, is it possible to use an array or something similar ?
Any help/input is appreciated