我是tkinter的新手。我们正在创建一个密码管理器软件,该软件的左侧有一个按钮框,右侧有一个内容。我想在右侧切换内容取决于按钮的点击情况。
我尝试了在网上找到的其他选项,但没有得到想要的结果。
from tkinter import *
from tkinter import ttk
import tkinter as tk
root = tk.Tk()
root.wm_geometry("1000x700")
root.title("LockIt")
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=4)
root.rowconfigure(0, weight=1)
class Page(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
def show(self):
self.lift()
class MainView(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
# pages declarations
p1 = PasswordPage(self)
p2 = MediaPage(self)
p3 = DocumentPage(self)
#seperate main window in two frames
self.buttonframe = Frame(root, bg='lightgrey')
self.container = Frame(root, bg='white')
self.buttonframe.grid(row=0,column=0,sticky=(N, S, E, W))
self.container.grid(row=0,column=1,sticky=(N, S, E, W))
self.container.rowconfigure(0,weight=1)
self.container.columnconfigure(0, weight=1)
p1.grid(row=0,column=0,in_=self.container,sticky=(N, S, E, W))
p2.grid(row=0,column=0,in_=self.container,sticky=(N, S, E, W))
p3.grid(row=0,column=0,in_=self.container,sticky=(N, S, E, W))
# Button frame
my_pass_button = Button(self.buttonframe, text="Passwords", fg="Black", bg="grey", height=6,command=p1.lift)
my_pass_button.pack(side="top", fill=X)
my_med_button = Button(self.buttonframe, text="Media", fg="Black", bg="grey", height=6,command=p2.lift)
my_med_button.pack(side="top", fill=X)
my_doc_button = Button(self.buttonframe, text="Documents", fg="Black", bg="grey", height=6,command=p3.lift)
my_doc_button.pack(side=TOP, fill=X)
class PasswordPage(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = tk.Label(self, text="This is page 1")
label.pack(side="top", fill="both", expand=True)
class MediaPage(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = tk.Label(self, text="This is page 2")
label.pack(side="top", fill="both", expand=True)
class DocumentPage(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = tk.Label(self, text="This is page 3")
label.pack(side="top", fill="both", expand=True)
main = MainView(root)
root.mainloop()
回溯(最近通话最近):文件 “ C:/用户/ Kate /桌面/ Seneca /学期 6 / PRJ666 / lockit / PrototypeTry.py“,第194行,在 main = MainView(root)File“ C:/ Users / Kate / Desktop / seneca / semester 6 / PRJ666 / lockit / PrototypeTry.py“,第75行,初始化 p1.grid(row = 0,column = 0,in_ = self.container,sticky =(N,S,E,W))文件 “ C:\ Users \ Kate \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ tkinter__init __。py”, 第2226行,在grid_configure中 + self._options(cnf,kw)) _tkinter.TclError:无法将。!mainview。!passwordpage放入。!frame2
以退出代码1完成的过程