This is the smaller version of my bigger program. When I hit the "Forward" Button
on "Week 1", it should print "Hi, from Week 2", however it's still printing "Hi, from Week 1."
Just to make sure I am assigning the correct button widget because this widget appeared at several places, So I used the line below just to test and it worked to the specific widget that I want.
self.parent.parent.sheet_dict["Week2"].upper_tabs_dict["Final"].button.configure(text = "red")
I don't know why my forward(self):
function is not working.
Thanks for taking the time to assist me in this.
Here is the complete code:
import tkinter as tk
from tkinter import ttk
from functools import partial
class Application(tk.Tk):
def __init__(self):
super().__init__()
self.title("notbook my own try")
self.geometry("700x450")
self.config(bg="tan")
self.style = ttk.Style() # instantce of ttk.Style() class.
self.lnb = Sheets(self) #composition (application has child)
class Sheets(ttk.Notebook): #contains the weeks tabs
def __init__(self, parent): #parent is root, which is tk.
parent.style.configure("down.TNotebook", tabposition="sw")
super().__init__(parent, style = "down.TNotebook")# this parent
is Notebook class.
self.pack(fill = tk.BOTH, expand =1)
self.parent = parent
self.week_index = ['Week 1', 'Week 2',"Week 3", "Week 4"] #
self.sheet_dict = {} #holds all the One_Weekly_Notebook's
instances
for week in (self.week_index):
self.week = One_Weekly_Notebook(self)#create instances
self.week.pack()
self.add(self.week, text = week)
self.pack()
self.sheet_dict[week] = self.week
class One_Weekly_Notebook(ttk.Notebook): #contains the tabs
def __init__(self, parent):
super().__init__(parent)
self.pack(fill = tk.BOTH, expand =1)
self.parent = parent
self.upper_tabs_dict = {}
self.calculate_buttons_dict = {} #to store all the calculate
buttons in differnt weeks
self.object_final = Final(self)
self.object_requests = Requests(self)
self.object_control = Control(self)
tab1 = self.object_final #child of lower notebook
tab2 = self.object_requests
tab3 = self.object_control
tab1.pack()
tab2.pack()
tab3.pack()
self.add(tab1, text = "Final")
self.pack()
self.add(tab2, text = 'Requests')
self.pack()
self.add(tab3, text = 'Control')
self.pack()
self.upper_tabs_dict["Final"] = tab1
self.upper_tabs_dict["Requests"] = tab2
self.upper_tabs_dict["Control"] = tab3
def display_results(self, button): #layer 3
self.say_hi(button)
def say_hi(self,button): #layer 3
self.id =
self.parent.parent.lnb.index(self.parent.parent.lnb.select())+1
# button=
self.parent.parent.lnb.index(self.parent.parent.lnb.select())+1
print (f"Hi from {button}")#current tap #)
class Final(tk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.pack(fill=tk.BOTH, expand=1)
self.parent = parent
self.buttons()
def buttons(self):
self.button = tk.Button(self, text="Say Hi", bg="salmon")
self.button.configure(command= lambda button=self.button:
self.parent.display_results(button))
self.button.pack()
self.parent.calculate_buttons_dict = self.button
self.buttonc = tk.Button(self, text = "Forward", command =
self.forward)
self.buttonc.pack()
print (self.parent.calculate_buttons_dict)
def forward(self):
self.parent.display_results(self.parent.parent.sheet_dict["Week
1"].upper_tabs_dict["Final"].button)
self.parent.display_results(self.parent.parent.sheet_dict["Week
2"].upper_tabs_dict["Final"].button)
self.parent.display_results(self.parent.parent.sheet_dict["Week
3"].upper_tabs_dict["Final"].button)
self.parent.display_results(self.parent.parent.sheet_dict["Week
4"].upper_tabs_dict["Final"].button)
class Requests(Final):
pass
class Control(tk.Frame):
pass
if __name__ == '__main__':
Application().mainloop()
enter code here