In this example, I have an entry and two LabelFrames. I am looking to find out how I can call my LabelFrame through only one function. I have written this code as an example.
import tkinter as tk
class Data:
def __init__(self):
self.number = tk.StringVar()
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.minsize(700, 700)
container = tk.Frame(self)
container.pack()
self.data = Data()
self.frames = {}
for F in (PageOne, ):
frame = F(container, self.data)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
def show_frame(self, c):
frame = self.frames[c]
frame.tkraise()
class PageOne(tk.Frame):
def __init__(self, parent, data):
super().__init__(parent)
self.data = data
entry1 = tk.Entry(self, textvariable=self.data.number)
entry1.pack()
self.button1 = tk.Button(self, text="click", command=self.add)
self.button1.pack()
self.frame1 = tk.LabelFrame(self, height=200, width=200, borderwidth=2)
self.frame1.pack()
self.button2 = tk.Button(self, text="click", command=self.add)
self.button2.pack()
self.frame2 = tk.LabelFrame(self, height=200, width=200, borderwidth=2)
self.frame2.pack()
def add(self):
self.frame1.config(text=str(self.data.number.get()))
app = SampleApp()
app.mainloop()Currently, I have used add() function to add a title for frame1 through button1. But how I can add a title for the other frame using the add() function again through button2. How I can get any frame as an argument through the function?
