在Tkinter中切换帧时出错

时间:2018-04-25 22:09:10

标签: python python-3.x tkinter

我正在尝试将python GUI作为学校课程的一部分,我正在尝试使用按钮切换帧,设置为销毁旧框架并打开新框架,而我没有任何问题打开一个新框架我似乎无法破坏旧框架或将任何小部件等加载到新框架中。以下是我遇到问题的代码部分:

class welcomePage(tk.Frame):

def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.controller = controller

    homebutton = tk.Button(self, text = "Return Home", command=lambda: self.home(), width = 30, height = 1)
    homebutton.pack(padx = 10, pady= 20 )

    cswitch = tk.Button(self, text = "Customer Interface", command=lambda: (self.destroy, CustomerPage()), width = 30, height = 1)
    cswitch.pack(padx = 10, pady= 15 )

    exit = tk.Button(self, text="Exit", command=self.destroy, width = 30, height = 1)
    exit.pack(padx = 10, pady= 20 )

class CustomerPage(tk.Tk):
def __init__(self, *args, **kwargs):
    tk.Tk.__init__(self, *args, **kwargs)


    self.title("Customer Interface")
    self.minsize(width = 300, height = 100)
    self.maxsize(width = 9999, height = 9999)
    tab_control = tk.Notebook(self)
    admin1 = tk.Frame(tab_control)
    admin2 = tk.Frame(tab_control)
    admin3 = tk.Frame(tab_control)
    admin4 = tk.Frame(tab_control)
    tab_control.add(admin1, text='Menu')
    tab_control.add(admin2, text='DataBase')
    tab_control.add(admin3, text='Sales History')
    tab_control.add(admin4, text='Search')        

                # -- Menu -- #

    homebutton = tk.Button(admin1, text = "Return Home", command=lambda: self.home(), width = 30, height = 1)
    homebutton.pack(padx = 10, pady= 30 )

    cswitch = tk.Button(admin1, text = "Admin Interface", command=lambda: self.cswitch(), width = 30, height = 1)
    cswitch.pack(padx = 10, pady= 10 )

    exit = tk.Button(admin1, text="Exit", command=self.destroy, width = 30, height = 1)
    exit.pack(padx = 10, pady= 30 )

以下是我得到的错误:AttributeError:模块'tkinter'没有属性'Notebook'

我无法在网上找到有关此特定错误的任何内容,因此非常感谢任何帮助:)。

1 个答案:

答案 0 :(得分:0)

这应该有效:

from tkinter import ttk

tab_control = ttk.Notebook(self)