Hello, I modified your code to make it work:
http://paste-it.net/public/m46ae5d/ Certainly, to be able to re-write the code, I made some assumptions and guesses about your original intentions. Just check the code to see if it is close to what you want. Firat 2010/9/21 Devred, Emmanuel <emmanuel.dev...@dfo-mpo.gc.ca> > Hello, > I am a total beginner with python and tkinter and I am having a hard time > getting my program working, I think the problem come from passing variables. > > I would like to have a menu that would with three main buttons, the first > one (LUT) let me chosse between two files, the second button (rrs) opens a > browser to choose a file and the third button would run a program (or > function) that makes some computation between the two files open with button > 1 and button 2, > > Here is what I have written > > from Tkinter import * > from tkFileDialog import askopenfilename > import numpy as np > > class openfile(): > def __init__(self, yn): > if yn == 0 : self.lut = > np.loadtxt("C:\python26\LUTnpdi_chile",dtype=np.float,skiprows=1) > if yn == 1 : self.lut = > np.loadtxt("C:\python26\LUTnpdi_nwa",dtype=np.float,skiprows=1) > if yn == 2 : filename = > askopenfilename(filetypes=[("allfiles","*"),("pythonfiles","*.py")]) > if yn == 2 : self.lut = > np.loadtxt(filename,dtype=np.float,skiprows=1) > > Class rrs_file(self,rrs): > filename = > askopenfilename(filetypes=[("allfiles","*"),("pythonfiles","*.py")]) > rrs = np.loadtxt(filename,dtype=np.float,skiprows=1) > > def make_comp(): > result = self.lut[1,2] * rrs[1,2] > print result > > def callback(): > print "called the callback!" > > root = Tk() > > # create a menu > menu = Menu(root) > root.config(menu=menu) > > filemenu = Menu(menu) > menu.add_cascade(label="LUT", menu=filemenu) > filemenu.add_command(label="East Pacific", command=lambda:openfile(0)) > filemenu.add_command(label="NW Atlantic", command=lambda:openfile(1)) > > image_menu = Menu(menu) > menu.add_cascade(label="Rrs", command=rrs_file) > > run_menu = Menu(menu) > menu.add_cascade(label="Run", command = make_comp) > > quitmenu = Menu(menu) > menu.add_cascade(label="Quit", command=root.destroy) > > #x = openfile(2) > > mainloop() > > I can not figure out how to pass get the lut and rrs parameters that I have > defined in the class objects? > > I need help !!! > > Thank you very much in advance. > > Emmanuel > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > >
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss