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

有帮助吗?

解决方案

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()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top