在Tkin中切换帧时出错

2024-09-28 17:27:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试一个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”

我在网上找不到有关此特定错误的任何信息,因此非常感谢您的帮助:)。你知道吗


Tags: textselfbuttonwidthframetabcommandpack