[Tkinter-discuss] (no subject)

Firat Ozgul ozgulfirat at gmail.com
Wed Sep 22 21:53:23 CEST 2010


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.Devred at 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 at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20100922/55b1b827/attachment.html>


More information about the Tkinter-discuss mailing list