I want to create a PanedWindow with variable number of panes which every one of these panes includes a label and a button. Pressing a button in a pane should write a messege to the corresponding label in that pane. I tried this code:
from tkinter import *
from tkinter import ttk
n = 5
root = Tk()
root.geometry('250x500+100+100')
p = ttk.Panedwindow(root, orient=VERTICAL)
p.grid(column=0, row=0, sticky=(N, S, W, E))
for i in range(n):
pane = ttk.Labelframe(p, width=25, borderwidth=0)
p.add(pane)
def writeToLabel():
paneLabel.config(text='This is Pane number %d' %(i+1))
paneLabel = ttk.Label(pane, width=20, relief='solid')
paneButton = ttk.Button(pane, text='Press', command=writeToLabel)
paneButton.grid(column=0, row=0, padx=5)
paneLabel.grid(column=1, row=0, padx=5)
root.rowconfigure(0, weight=1)
root.mainloop()
But no matter which button is pressed the label in the last row is set with the message.
I would be grateful if somebody could help me to fix the problem.