Title: RE: [Tkinter-discuss] calling toplevel creating function

Hi Michael,

my code is below. actually the problem that I explained in my previous mail can be solved by using newkey() instead of self.newkey() toplevel definition.(but still could not understand what is the reason of the error message) however, still I could not reach my aim. As you will see below, I could not assign self.userkey which is gotten from the user on toplevel window, to the userdefinedkey[] array. the aim is, at first click of a key should result with a toplevel window that gets the key parameter from the user. the other press of the same key should result by calling a different function with the parameter taken. there are more than one such a key on my GUI. I hope, I can explain my aim and problems:) thanks from now...



from Tkinter import *

root = Tk()

class myentryclass:
    def __init__(self, parent):
        self.myParent = parent
        self.myParent.focus_set()
       
        self.mycontainer = Frame(parent, borderwidth=0)
        self.mycontainer.pack()


        userdefinedkeys=[]
        for i in range (2):
            userdefinedkeys.append('')

        button_name=self.userdefinedkeys[0]
        button_number=1
        self.key1=Button(self.mycontainer,
                           command=lambda
                            arg1=button_name, arg2=button_number:
                            self.Button_Press(arg1, arg2)
                           )
        self.key1.configure(text="key1")
        self.key1.grid(row=3, column=0)

        button_name=self.userdefinedkeys[1]
        button_number=2
        self.key2=Button(self.mycontainer,
                           command=lambda
                            arg1=button_name, arg2=button_number:
                            self.Button_Press(arg1, arg2)
                           )
        self.key2.configure(text="key2")
        self.key2.grid(row=3, column=1)


    def Button_Press(self, arg1, arg2):
        if arg2==1:
            if arg1=='':
                self.newkey()
                self.userdefinedkeys[0]=self.userkey
            else:
                print self.userdefinedkeys[0]
        if arg2==2:
            if arg1=='':
                self.newkey()
                self.userdefinedkeys[1]=self.userkey
            else:
                print self.userdefinedkeys[1]

        else:
            pass
    
    def newkey(self):
            newkey=Toplevel()
            newkey.title('Define New Key')
            newkey.geometry('250x140+500+300')

            self.keydef = Label(newkey, text="Key Name:")
            self.keydef.place(x=10, y=10)
            self.keyname = Entry(newkey)
            self.keyname.focus_set()
            self.keyname.place(x=90, y=10)
            confirm = Button(newkey, text="OK", width=15, command=self.getkeyname)
            confirm.place(x=67, y=85)
           
    def getkeyname(self):
        self.userkey=self.keyname.get()
##        self.newkey.destroy()
        print self.userkey
        return self.userkey        

  
    def sendcommand(self, arg1):
        print arg1


mylittlentry = myentryclass(root)
root.mainloop()



-----Original Message-----
From: [EMAIL PROTECTED] on behalf of Michael Lange
Sent: Tue 5/30/2006 12:30 AM
To: [email protected]
Subject: Re: [Tkinter-discuss] calling toplevel creating function

On Mon, 29 May 2006 14:54:28 +0300
"Ilknur Ozturk" <[EMAIL PROTECTED]> wrote:

> Hi all,
>

>
> I have a problem with toplevel window. It is created within a function
> and I am calling that function by button press. I have created 4 buttons
> that call same toplevel creating function. For the first call, there is
> no problem. The toplevel window is created and get the arguments. But
> the other call for that function results with an error message like;
>

>
> "Toplevel instance has no __call__ method"
>

Hi Ilknur,

can you show us the code and a complete traceback, otherwise we can only guess.
The error message you described can be reproduced by the folllowing code snippet:

>>> t=Toplevel()
>>> t()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: Toplevel instance has no __call__ method
>>>

so maybe the problem is the name you give to your Toplevel instance.

Michael
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to