【问题标题】:Python tkinter ttk.Notebook widget errorPython tkinter ttk.Notebook 小部件错误
【发布时间】:2013-09-21 19:11:17
【问题描述】:

我在使用 python 3.3.2 的笔记本小部件时遇到问题

这是代码:

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

这是错误:

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'

我不知道错误的原因

谢谢

【问题讨论】:

    标签: python widget tkinter attributeerror ttk


    【解决方案1】:

    问题在于您将grid 函数的结果分配给n,而不是Notebook 小部件本身。 grid 函数总是返回None,所以n 的值是None,因此报错。

    要解决此问题,请尝试替换此行

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

    这些行

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多