return from class? 
Author Message
 return from class?

I use python and Tkinter.
I have "Add product" window:

NAME: [.entry.]
PRICE: [.entry.]
PRODUCER: [.label.] [Button]

When I click "button" - another window should open, with Listbox of
corporations, then I should select on corporation and click "OK" in that
window, then id of that corporation should be returned to this "add product
window".
So I created other class - with listbox, scrollbar, button, but I don't know
what should I write in command function for button "OK". Class instance should
be destroyed and return value - id of selected corporation. How to do this?

--
She never breaks into the conversation  He seems to be the reason why she lives
She tries to be the perfect kind of stranger                
But we always seem to love the most                        
The ones who never give                "Between Two Hearts" - Ronnie James Dio



Thu, 27 Nov 2003 18:20:21 GMT  
 return from class?
I will try to explain this better...
I need to select "corporation". I need it in many places in my application, so
I decided to create class SelectCorporation. This class should open window with
Listbox. User should select one item from that Listbox, then click "OK".
I don't know what to do when OK is clicked. I should destroy window, and class
instance, but how to return value to the class which called SelectCorporation?

--
Hot wind, moving fast across the desert
We feel that our time has arrived
The world spins, while we put his dream together                    "Stargazer"
A tower of stone to take him straight to the sky            - Ronnie James Dio



Thu, 27 Nov 2003 20:21:38 GMT  
 return from class?
Well.. I installed Pmw, so now I can use ComboBox instead of creating another
window with ListBox, but I still don't know how to create this special class...

--
They say that life's a carousel  
Spinning fast, you've got to ride it well
The world is full of kings and queens                         "Heaven and Hell"
Who blind your eyes and steal your dreams                   - Ronnie James Dio



Thu, 27 Nov 2003 22:58:56 GMT  
 return from class?
On Sun, 10 Jun 2001 12:21:38 +0000 (UTC), Jacek Pop3awski

Quote:

>I will try to explain this better...  I need to select
>"corporation". I need it in many places in my application, so I
>decided to create class SelectCorporation. This class should open
>window with Listbox. User should select one item from that Listbox,
>then click "OK".  I don't know what to do when OK is clicked. I
>should destroy window, and class instance, but how to return value to
>the class which called SelectCorporation?

Dear Jacek,
Thanks for working to make your question as clear as possible. In fact
it was very clear from the start. I remember having the same problem
myself.

I think that the easiest way to solve it is to look at the problem the
other way round. That is, instead of having an entry that is trying to
pull a value from your new window, let the new window push the value
into the entry. The only trick is to give your sub-window a reference
to the entry that it will want to put the value in. I'll append an
example of what I mean.

Best regards,
Matt

from Tkinter import *

class mainWin:

  def __init__(self,root):
    self.e=Entry(root)
    self.e.pack()
    b=Button(root,text="Sub-window",command=self.newWin)
    b.pack()
    return None

  def newWin(self):
    subWin(self.e)
    return None

class subWin:
  def __init__(self,mainWinEntry):
    self.mainWinEntry=mainWinEntry
    self.t=Toplevel()
    b=Button(self.t,text="Push",command=self.putTextInEntry)
    b.pack()
    return None

  def putTextInEntry(self):
    self.mainWinEntry.insert(END,"Wibble")
    self.t.destroy()
    return None

def main():
  root=Tk()
  mainWin(root)
  root.mainloop()

if __name__=="__main__":
  main()



Fri, 28 Nov 2003 02:01:30 GMT  
 return from class?

Quote:

> I think that the easiest way to solve it is to look at the problem the
> other way round. That is, instead of having an entry that is trying to
> pull a value from your new window, let the new window push the value
> into the entry.

yes, that is the solution
however, as I told before - I installed Pmw and now I can use ComboBox inside
my window, so I don't need another class, but probably soon I will have the
same problem again, and now I have idea how to solve it - thanks a lot!

--
From the book the word is spoken
Whispers from forgotten psalms
Gather all around the young ones                   "Sign of the Southern Cross"
They will make us strong                                    - Ronnie James Dio



Fri, 28 Nov 2003 05:38:58 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Returning derived classes

2. Returning a class/interface from a function

3. Returning a class.

4. access on function returning a class wide type

5. returning base class pointer from function

6. Q: returning python class instance from c-module

7. Java Object Not Returned/Java Class Not Preserved

8. D4PL1BUG: Database Connection DBResultSet>>species returns wrong class...

9. Simple question "how to return a class not a instance"

10. The return method of the LIST class in the ISE 2.3 libraries

11. 1st-class method closures (was Re: Multiple return values)

12. "class" return value

 

 
Powered by phpBB® Forum Software