Creating a Simple User Interface for a Function

CTSB01 scott.moore270 at gmail.com
Thu Jul 25 22:58:33 CEST 2013


On Thursday, July 25, 2013 3:19:27 PM UTC-4, Dave Angel wrote:
> On 07/25/2013 12:03 PM, CTSB01 wrote:
> 
> > I have the following code that runs perfectly:
> 
> 
> >       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
> 
> No it doesn't run perfectly.  It'll get a syntax error on the print 
> 
> function call.  That's assuming you're still using Python 3.3.  You 
> 
> really need to start by specifying your environment, without making us 
> 
> look back through previous threads from you.
> 
> > This code takes a string x = [0,1,1,1,2] for example
> 
> That's not a string.  A string would be like
> 
>     xx = psi_j("0abcd1234")
> 
> Perhaps you mean list?  And is it a list of integers, or of arbitrary 
> 
> numbers?  Are there any constraints on the sizes or signs of those numbers?
> 
> > (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.
> 
> Only if you replace the / with //.  Or just use the function divmod():
> 
>        n, r = divmod(n2, m)
> 
> >  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
> 
> So far you have a function, not a program.  If you put it in a text file 
> 
> and run it from python, it'll do nothing but display a syntax error 
> 
> message.  And when you fix that, it'll just run without doing anything.
> 
>   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,
> 
> > and then displays the output sequence.  This is essentially what the program already does but the idea is to make it usable
> 
> > for even the most technologically disinclined.  Ideally it would do this without needing to run Python at all.
> 
> Then why are you asking on the Python forum?  Or perhaps you mean 
> 
> without him knowing he's running Python?  In that case, use a shebang 
> 
> line at the beginning, which will tell Linux to automatically invoke the 
> 
> specified program (or programming language in this case).
> 
> >  If anyone is able to make this happen in Python I would be eternally grateful.
> 
> If we assume you're running Python 3.3 on Linux, and the user is willing 
> 
> to us the terminal, then how about parsing the string from the command 
> 
> line he types?  You can access it as011123334 a string from sys.argv, 
> 
> and convert it to separate numbers.  Of course as it stands now, you 
> 
> cannot tell whether the user wanted
> 
>    0,1,1,1,2,3,3,3,4
> 
> or
> 
>    0, 111, 23, 3, 3, 4
>
> or something else.
> 
> DaveA

Sorry Dave, to answer each part of your response:

1) I decided to use Python 2.7, and I will be sure to specify this in all future threads.
2) It is a list of positive integers.  In fact, it is always going to be a list of positive increasing integers.
3) You're right.  What I meant was that if after running that bit of code I enter
>>> x = [0,1,2,3,4,5]
>>> psi_j(x,2) 
I will get output that matches my requirements.
4) Yes, sorry that's what I meant (if I understood correctly).  I was told elsewhere that I might want to try using tkinter.  Essentially I'm trying to create a user interface that allows the user to just type in a string 01112345 for example, and choose a parameter (say j=2) and then click a button to run the function.  I'd like to be able to run send a .exe file that the user can just open up and use with no further setup.  

So on top of the user interface I would also it looks like need to determine how to make Python change a string 01112345 into a list so that it does that automatically when the user clicks 'run'.  

Would a shebang still be the right way to go?  

Thanks again Dave, apologies for the ambiguity.



More information about the Python-list mailing list