[Tutor] Calling a python program from a program menu

Keule m_konermann@gmx.de
Fri, 15 Feb 2002 11:00:30 +0100


--------------050901010108030302080801
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

  HI @ All

I want to call a python script, consist of an entry widget (like below)


# variablen.py
from Tkinter import *
from quitter import Quitter
fields = 'Minimalwert', 
'Maximalwert','Pre-Kondition','Post-Kondition','Zeile','Spalte'

def fetch(entries):
    for entry in entries:
        print 'Input => "%s"' % entry.get()         # get text
    print 'entries=',entries

def makeform(root, fields):
    entries = []
    for field in fields:
        row = Frame(root)                                       # make a 
new row
        lab = Label(row, width=15, text=field)       # add label, entry
        ent = Entry(row)
        row.pack(side=TOP, fill=X)                          # pack row 
on top
        lab.pack(side=LEFT)
        ent.pack(side=RIGHT, expand=YES, fill=X)    # grow horizontal
        entries.append(ent)
    return entries

if __name__ == '__main__':
    root = Tk()
    root.title('Variableneingabe')
    ents = makeform(root, fields)
    root.bind('<Return>', (lambda event, e=ents: fetch(e)))   
    Button(root, text='nächste Variable',command=(lambda e=ents: 
fetch(e))).pack(side=LEFT)
    Quitter(root).pack(side=RIGHT)
    root.mainloop()

from another script, consist of a complete program menu

 def makemenu(win):
    top = Menu(win)                                    # win=top-level 
window
    win.config(menu=top)                           # set its menu option

     Variablen = Menu(top)
    Variablen.add_command(label=    'Neu',          command=variablen.py 
,  underline=0)
    top.add_cascade(label=          'Variablen',    menu=Variablen,   
underline=0)
     .....

but there seems to be a mistake in the calling sequence 
 command=variablen.py .
Have anyone got an idea ?

Greetings
Marcus





--------------050901010108030302080801
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html>
<head>
</head>
<body>
   HI @ All<br>
<i><br>
</i>I want to call a python script, consist of an entry widget (like below)<br>
<i><br>
<br>
 # variablen.py<br>
 from Tkinter import *<br>
 from quitter import Quitter<br>
 fields = 'Minimalwert', 'Maximalwert','Pre-Kondition','Post-Kondition','Zeile','Spalte'<br>
<br>
 def fetch(entries):<br>
 &nbsp;&nbsp;&nbsp; for entry in entries:<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Input =&gt; "%s"' % entry.get()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # get text<br>
 &nbsp;&nbsp;&nbsp; print 'entries=',entries<br>
<br>
 def makeform(root, fields):<br>
 &nbsp;&nbsp;&nbsp; entries = []<br>
 &nbsp;&nbsp;&nbsp; for field in fields:<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; row = Frame(root)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # make a 
new row<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lab = Label(row, width=15, text=field)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # add label, entry<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ent = Entry(row)<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; row.pack(side=TOP, fill=X)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # pack row on 
top<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lab.pack(side=LEFT)<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ent.pack(side=RIGHT, expand=YES, fill=X)&nbsp;&nbsp;&nbsp; # grow horizontal<br>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entries.append(ent)<br>
 &nbsp;&nbsp;&nbsp; return entries<br>
<br>
 if __name__ == '__main__':<br>
 &nbsp;&nbsp;&nbsp; root = Tk()<br>
 &nbsp;&nbsp;&nbsp; root.title('Variableneingabe')<br>
 &nbsp;&nbsp;&nbsp; ents = makeform(root, fields)<br>
 &nbsp;&nbsp;&nbsp; root.bind('&lt;Return&gt;', (lambda event, e=ents: fetch(e)))&nbsp; &nbsp;<br>
 &nbsp;&nbsp;&nbsp; Button(root, text='n&auml;chste Variable',command=(lambda e=ents: fetch(e))).pack(side=LEFT)<br>
 &nbsp;&nbsp;&nbsp; Quitter(root).pack(side=RIGHT)<br>
 &nbsp;&nbsp;&nbsp; root.mainloop()<br>
<br>
</i>from another script, consist of a complete program menu<i><br>
<br>
 &nbsp;def makemenu(win):<br>
 &nbsp;&nbsp;&nbsp; top = Menu(win)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # win=top-level window<br>
 &nbsp;&nbsp;&nbsp; win.config(menu=top)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # set its menu option<br>
<br>
 &nbsp;&nbsp; &nbsp; Variablen = Menu(top)<br>
 &nbsp;&nbsp;&nbsp; Variablen.add_command(label=&nbsp;&nbsp;&nbsp; 'Neu',&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </i><b>command=variablen.py</b>
,&nbsp; underline=0)<br>
 &nbsp; &nbsp;<i> top.add_cascade(label=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Variablen',&nbsp;&nbsp;&nbsp; menu=Variablen,&nbsp;&nbsp;
underline=0)<br>
&nbsp;&nbsp;&nbsp;&nbsp; .....</i><br>
<br>
but there seems to be a mistake in the calling sequence &nbsp;<b>command=variablen.py</b>
.<br>
Have anyone got an idea ?<br>
<br>
Greetings<br>
Marcus<br>
<br>
<br>
<br>
<br>
</body>
</html>

--------------050901010108030302080801--