首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python尝试使用选项卡控件时出错: Tkinter没有属性Notebook

Python尝试使用选项卡控件时出错: Tkinter没有属性Notebook
EN

Stack Overflow用户
提问于 2019-03-21 21:53:38
回答 2查看 1.2K关注 0票数 0

我正在尝试将选项卡控件添加到我的GUI。然而,我得到了这个错误: AttributeError: module tkinter没有'Notebook‘属性。其他Tkinter对象工作得很好,比如按钮、标签、画布。

你知道这是什么原因造成的吗?

另请参阅REPL中的相同内容:

代码语言:javascript
运行
复制
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'

下面是我的代码:

代码语言:javascript
运行
复制
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,并得到了相同的结果:

代码语言:javascript
运行
复制
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'

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-21 22:26:21

ttk是tkinter的一个子模块,需要导入。比我以前使用的例子更好的例子:Notebook widget in Tkinter

票数 1
EN

Stack Overflow用户

发布于 2021-05-30 13:28:28

这是因为Notebook小部件不属于Tkinter模块。您需要从Tkinter导入它。ttk。例如:

from Tkinter import ttk

ttk.notebook(root)...诸若此类

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55282022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档