简体   繁体   中英

Python tkinter ttk.Notebook widget error

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM