I am trying to code, for the first time, a GUI containing a NoteBook overlay under tkinter. I can't click on the buttons to activate the right NoteBook and delete the other one. Is it possible to have some advice.
# ---------- Library ----------
import tkinter as tk
from tkinter import *
from tkinter import ttk
---------- Class ---------
class MainFrame(tk.Tk):
def __init__(self):
# initialization
self.Asperge = Tk()
# Definition
Main_Title = "Test : notebook overlay"
self.Asperge.geometry("700x550")
self.Asperge.resizable(False, False)
self.Asperge.wm_title(Main_Title)
self.Asperge.configure(bg = "CadetBlue1")
# Add widgets on Main Frame
self.Create_Widgets()
# Children Main for NoteBook1 and NoteBook2
#Frame_NoteBook1 = tk.Frame(self.Asperge, width = 660, height = 400, bg = "OliveDrab1")
#Frame_NoteBook1.place(x = 20, y = 80)
#Frame_NoteBook2 = tk.Frame(self.Asperge, width = 660, height = 400, bg = "sandy brown")
#Frame_NoteBook2.place(x = 20, y = 80)
# Widget definition
def Create_Widgets(self):
# add Quit Button
Button_Quit = tk.Button(self.Asperge, text="Exit",
width=20,
height=2,
command = self.Asperge.destroy
)
Button_Quit.place(x= 20, y= 500)
# Button NoteBook1
Button_NoteBook1 = tk.Button(self.Asperge, text="NoteBook 1",
width = 20,
height = 2,
#command=self.Create_NoteBook_1()
)
Button_NoteBook1.place(x = 150, y = 20)
# Button NoteBook2
Button_NoteBook2 = tk.Button(self.Asperge, text="NoteBook 2",
width = 20,
height = 2,
#command = self.Create_NoteBook_2()
)
Button_NoteBook2.place(x = 350, y = 20)
# NoteBook 1
def Create_NoteBook_1(self):
Frame_NoteBook1 = tk.Frame(self.Asperge, width = 660, height = 400, bg = "OliveDrab1")
Frame_NoteBook1.place(x = 20, y = 80)
Tab_List1 = ["Name 11", "Name 12", "Name 13", "Name 14", "Name 15", "Name 16",]
NoteBook1 = ttk.Notebook(Frame_NoteBook1)
NoteBook1.place(x = 0, y= 0)
for tab_number in range(len(Tab_List1)):
Tab_NoteBook1 = ttk.Frame(NoteBook1, width = 660, height = 400)
NoteBook1.add(Tab_NoteBook1, text = Tab_List1[tab_number])
# NoteBook 2
def Create_NoteBook_2(self):
Frame_NoteBook2 = tk.Frame(self.Asperge, width = 660, height = 400, bg = "sandy brown")
Frame_NoteBook2.place(x = 20, y = 80)
Tab_List2 = ["Name 21", "Name 22", "Name 23"]
NoteBook2 = ttk.Notebook(Frame_NoteBook2)
NoteBook2.place(x = 0, y= 0)
for tab_number in range(len(Tab_List2)):
Tab_NoteBook2 = ttk.Frame(NoteBook2, width = 660, height = 400)
NoteBook2.add(Tab_NoteBook2, text = Tab_List2[tab_number])
# ---------- Main ----------
if __name__ == "__main__":
app = MainFrame()
app.Asperge.mainloop()
CodePudding user response:
You've commented out your commands for the notebook buttons. Also, there is no logic for deleting the other notebook, not sure if one would "draw" over the other, though.
CodePudding user response:
One approach would be to store your Frames in the initialization so you can call destroy() for the other Frame from each create method.