【发布时间】:2019-08-12 09:38:40
【问题描述】:
我正在尝试将选项卡控件添加到我的 GUI。但是我收到此错误:AttributeError:模块 tkinter 没有属性“笔记本”。其他 Tkinter 对象工作得很好,例如按钮、标签、画布。
有什么想法会导致这种情况吗?
在 REPL 中也可以看到相同的内容:
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.notebook()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'notebook'
>>> tkinter.Notebook()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'Notebook'
这是我的代码:
import tkinter as tk
class Tab1():
def __init__(self, master):
self.frame = tk.Frame(master)
self.frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
self.tabControl = tk.Notebook(self.frame)
我安装了较新版本的 Python,得到了相同的结果:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.Notebook()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'Notebook'
【问题讨论】:
-
错误告诉你问题出在哪里:tkinter 没有笔记本。但是,ttk 模块可以。
-
布莱恩,谢谢。我看过的所有例子都没有说明 Notebook 是 ttk 的一部分,它是 tkinter 的一个子模块。他们只是使用 ttk,所以我以为这是他们在导入 tkinter 时使用的名称!
标签: python-3.x tkinter tabs