Home > Back-end >  Tkinter entry widget - typed values gets copied to other entries
Tkinter entry widget - typed values gets copied to other entries

Time:10-27

I am trying to create multiple Entry widgets on different pages of a notebook widget. However, when I type something in one Entry, it gets automatically copied to corresponding Entry on all pages. Please help. Here is my code.

import tkinter as tk
from tkinter import ttk
from tkinter import *

app = Tk()
nb = ttk.Notebook(app)

pages = []
canvas_left = []
canvas_right = []
entry_labels = []
entry_values = []

for i in range(3):
    pages.append(ttk.Frame(nb))
    canvas_left.append(tk.Canvas(pages[i], width=500, height=400, bd=0, highlightthickness=0))
    canvas_left[i].pack(side=LEFT)
    entry_values.append([])
    for j in range(8):
            entry_values[i].append(Entry(app, width=20, text="Window " str(j 1), fg="white", bg="gray", font=("Helvetica", 12)))
            canvas_left[i].create_window(125, 20   j*35, anchor="w", window=entry_values[i][j])
    nb.add(pages[i], text="Display " (i 1).__str__())
nb.pack(side=TOP)
app.mainloop()

CodePudding user response:

The text option of Entry widget is the same as textvariable option. So you use same variable name across the frames and they will be updated at the same time when one of them is updated.

Remove the text option from those Entry(...).

  • Related