0

I have a problem with the Notebook widget with python 3.3.2

This is the code:

gui=Tk()
gui.title("Test")
gui.geometry()

n = ttk.Notebook(gui).grid()
f1 = ttk.Frame(n)
f2 = ttk.Frame(n)
n.add(f1, text='One')
n.add(f2, text='Two')


gui.resizable(width=TRUE, height=TRUE)
mainloop()

and this is the error:

Traceback (most recent call last):
  File "C:\Users\SergiX\Desktop\SergiX44's ModTool con sorgente 3.3\SergiX44's ModTool 1.6.4.py", line 179, in <module>
    n.add(f1, text='One')
AttributeError: 'NoneType' object has no attribute 'add'

I don't know the reason of the error

thanks

1 Answer 1

2

The problem is that you're assigning the result of the grid function to n, rather than the Notebook widget itself. The grid function always returns None, so n has a value of None, thus the error.

To fix this, try replacing this line

n = ttk.Notebook(gui).grid()

with these lines

n = ttk.Notebook(gui)
n.grid()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.