我正在尝试将选项卡控件添加到我的GUI。然而,我得到了这个错误: AttributeError: module tkinter没有'Notebook‘属性。其他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'
发布于 2019-03-21 22:26:21
ttk是tkinter的一个子模块,需要导入。比我以前使用的例子更好的例子:Notebook widget in Tkinter
发布于 2021-05-30 13:28:28
这是因为Notebook小部件不属于Tkinter模块。您需要从Tkinter导入它。ttk。例如:
from Tkinter import ttk
ttk.notebook(root)
...诸若此类
https://stackoverflow.com/questions/55282022
复制相似问题