简体   繁体   English

Python tkinter ttk.Notebook小部件错误

[英]Python tkinter ttk.Notebook widget error

I have a problem with the Notebook widget with python 3.3.2 使用python 3.3.2的Notebook小部件有问题

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. 问题是您将grid函数的结果分配给n ,而不是Notebook小部件本身。 The grid function always returns None , so n has a value of None , thus the error. grid函数始终返回None ,因此n的值为None ,因此为错误。

To fix this, try replacing this line 要解决此问题,请尝试替换此行

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

with these lines 用这些线条

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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