Reputation: 397
I am trying to add a tab control to my GUI. However I'm getting this error: AttributeError: module tkinter has no attribute 'Notebook'. Other Tkinter objects work just fine, such as buttons, labels, canvas.
Any ideas what would cause this?
Also see same in 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'
Here's my code:
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)
I installed newer version of Python, and get same result:
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'
Upvotes: 2
Views: 2770
Reputation: 3011
It's because Notebook Widgets do not belong to Tkinter module. You need to import it from Tkinter. ttk. for example -
from Tkinter import ttk
ttk.notebook(root)
...
and so on
Upvotes: 0
Reputation: 397
ttk is a submodule of tkinter; it needed to be imported. Better example to review than those I previously used: Notebook widget in Tkinter
Upvotes: 2