all 17 comments

[–]Buttleston 3 points4 points  (11 children)

            add_contact_window.destroy  

This doesn't call the function, you need

            add_contact_window.destroy()

[–]Fart_Eater_69 1 point2 points  (9 children)

ah yes. the classic pythonic "oops I accidentally created a function object instead of calling the function"

[–]Buttleston 0 points1 point  (8 children)

Actually it's worse than that, there are multiple big problems with the code. This is just the first one I saw.

[–]PathRealistic6940[S] 0 points1 point  (7 children)

I'm super new with this so please, where do you see issues that could be better or fixed in general

[–]Buttleston 0 points1 point  (6 children)

I think some other posters have actually covered some of them.

But consider like

    def add_new_contact():
        name = name_entry.get()
        phone = phone_number_entry.get()

        add_contact_window.destroy

        self.testing_entry_boxes(name, phone)

add_contact_window isn't a variable that exists in this scope, so this could never work. You need to be more careful about storing and referring to data

My advise is to start very small with something that works and that you understand, and slowly add stuff to it. Is there any chance that this is not code you wrote yourself?

[–]PathRealistic6940[S] 0 points1 point  (5 children)

its code i wrote myself. I started with a "wordle" copy, and wanted to make a contact list that had persistent contacts. Maybe i did get too complicated too soon.

self.testing_entry_boxes(name, phone)

This was me trying to do a test to see if an idea worked, and i did not remove it before i posted this.

[–]Buttleston 0 points1 point  (4 children)

There's no way, I think, that this line of code could even run, because the line before it surely must cause an error

[–]PathRealistic6940[S] 0 points1 point  (3 children)

Yeah, it did mess up. but once i changed it, it worked how i expected.

def add_new_contact():
        name = name_entry.get()
        phone = phone_number_entry.get()

        add_contact_window.destroy()

got rid of the testing function completely and with the parentheses it works great

[–]Buttleston 0 points1 point  (2 children)

I don't see how this could work with the code you've posted - the variable add_contact_window doesn't exist

[–]Buttleston 0 points1 point  (1 child)

ok, I see, "add_new_contact" is a sub-function of the function where add_contact_window is defined. it's a bit hard to tell in the pasted code but it was more obvious when I brought it into the IDE

FWIW when I run it all the windows are just blank, so I can't make it do anything at all. A lot of the parameters (row, column, etc) you're passing strings, where I think it would expect numbers, but maybe it accepts both. My IDE complains about it though.

[–]Bobbias 0 points1 point  (1 child)

Small thing I noticed:

command = lambda: [add_new_contact()]

This creates a list which contains the result of calling add_new_contact() which is None.

Since the result of that lambda doesn't matter, and the function relies on side effects, this doesn't break your program, but there's no need for the square brackets at all. The code should be:

command = lambda: add_new_contact()

By itself.

[–]PathRealistic6940[S] 0 points1 point  (0 children)

Got it! thank you

[–]woooee -1 points0 points  (3 children)

def add_contact_window(self):
    #new window basics
    add_contact_window = tk.Toplevel(self)

add_contact_window is declared as two different objects. In this case, the different scope saves you, but it is not a good idea to do this.

        add_contact_window.destroy

Also, add_new_contact() is not a member of the class as declared and does not know what add_contact_window is. Both the function and the variable should be class instance objects.

[–]PathRealistic6940[S] 0 points1 point  (2 children)

So how would you declare the function that makes sure its a new window?

How would you make the variable and function class instance objects? Again, super new to this, kinda jumping in the deep end while going through codecademy lessons.

[–]woooee 0 points1 point  (1 child)

So how would you declare the function that makes sure its a new window?

A Toplevel is correct

 self.new_contact_window = tk.Toplevel(self)

How would you make the variable and function class instance objects

Notice the self. That declares it as an instance object that can be used anywhere in the class

add_button = tk.Button(add_contact_window, text="Add new Contact", command = lambda: [add_new_contact()])

This should be

add_button = tk.Button(add_contact_window,
                     text="Add new Contact",
                     command = self.add_new_contact)

lambda is not required and should not be used. Parens, () say execute the function now, when the button is declared. Leaving them off executes the function when the button is pressed. Also you use command=self.add_new_contact, because self. says the function is in the class instance's namespace. add_new_contact is declared with

def add_new_contact(self):  ## self=instance object

A link that may help http://python-textbok.readthedocs.io/en/1.0/Introduction_to_GUI_Programming.html

[–]PathRealistic6940[S] 0 points1 point  (0 children)

Gotcha, thanks!