Existing Tkinter Code that Takes an Input String to Another String
Question: I already posted about this, however, my purpose here is different. I believe
there should be code around that does something very similar to this. I was
hoping someone might have an idea of where to look for examples like this
(interfaces of functions that act on strings). Even better, does anyone have a
block of code they already have available? I'm just looking for a template to
base mine off of. Thanks in advance.

To give you an idea of what I mean, here's the function I have in mind:

    
    
     def psi_j(x, j):
          rtn = []
          for n2 in range(0, len(x) * j - 2):
            n = n2 / j
            r = n2 - n * j
            rtn.append(j * x[n] + r * (x[n + 1] - x[n]))
            print 'n2 =', n2, ': n =', n, ' r =' , r, ' rtn =', rtn
          return rtn
    

This code takes a string x = [0,1,1,1,2] for example (it must always begin
with 0) and a parameter j, say 2, and outputs a string (x = [0, 1, 2, 2, 2, 2,
2, 3] in this example).

It does this in two steps: First it decomposes some number m into a multiple
of j and a remainder. Then it runs this decomposition through a function on
the rtn.append line.

Notice that this has cj - 1 terms where c is the number of terms in the input
string and j is the parameter. Normally, we would like it to be able to
calculate cj terms. This is an issue with the function that I am more than
happy to put aside for the moment.

My key interest is to be able to make this program usable for someone who has
no knowledge of programming. In particular, I need some kind of user interface
that prompts the user to input a string (ideally just by putting in numbers in
the form 011123334 for example) and a parameter.

EDIT:

The error is on the third line, and python highlights the space to the right
of (self, master) in orange all the way to the end of the row.


Answer: If you're interested in making a user interface of this with Tkinter you can
use the following code:

    
    
    from Tkinter import *
    
    class App(Frame):
        def __init__(self, master):
            Frame.__init__(self, master)
            self.grid()
            self.create_widgets()
    
        def create_widgets(self):
            self.entryLabel = Label(self, text="Please enter a list of numbers (no commas):")
            self.entryLabel.grid(row=0, column=0, columnspan=2)
    
            self.listEntry = Entry(self)
            self.listEntry.grid(row=0, column=2, sticky=E)
    
            self.entryLabel = Label(self, text="Please enter an index value:")
            self.entryLabel.grid(row=1, column=0, columnspan=2, sticky=E)
    
            self.indexEntry = Entry(self)
            self.indexEntry.grid(row=1, column=2)
    
            self.runBttn = Button(self, text="Run Function", command=self.psiFunction)
            self.runBttn.grid(row=2, column=0, sticky=W)
    
            self.answerLabel = Label(self, text="Output List:")
            self.answerLabel.grid(row=2, column=1, sticky=W)
    
        def psiFunction(self):
            j = int(self.indexEntry.get())
            valueList = list(self.listEntry.get())
            x = map(int, valueList)
            if x[0] != 0:
                x.insert(0, 0)
            rtn = []
            for n2 in range(0, len(x) * j - 2):
                n = n2 / j
                r = n2 - n * j
                rtn.append(j * x[n] + r * (x[n + 1] - x[n]))
            self.answer = Label(self, text=rtn)
            self.answer.grid(row=2, column=2, sticky=W)
    
    
    if __name__ == "__main__":
        root = Tk()
        app = App(root)
        root.mainloop()
    

If you have any questions let me know; this works in python 2.7.

This program automatically adds a zero if the user forgets to and the format
for input is, for example, 01112.

You can use `rtn` later on as well; it is a list of results.

