Python Forum
[Tkinter] Python Newbie
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Python Newbie
#3
A couple of problems here. You are creating new StringVars every time you call give_values so there is no way these can be bound to an Entry. Even if you only created the StringVar's once, their attribute names (varXX) do not exist outside the function give_values, so you would have no way to get these variables and bind them to the entries. Finally, you cannot set textvariable="var00" and expect the Entry constructor to figure out which namespace to use to search for attribute "var00" and get a StringVar.

import tkinter as tk
from tkinter import *
 
root = tk.Tk()
variables = []

def give_values():
    return [var.get() for var in variables] # Makes a list calling get for each StringVar in variables
 
def init():
    for i in range(3):
        for j in range(3):
            frame = tk.Frame(
                master=root,
                relief=tk.RAISED,
                width=2,
                borderwidth=1
            )
            frame.grid(row=i, column=j)
            var = StringVar()
            variables.append(var)
            entry = tk.Entry(master=frame,
                             text=f"Row {i}\nColumn {j}",
                             textvariable=var)
            entry.pack()
 
 
init()
# b1 = Button(root, text="Done", width=10).grid(row=0, column=10, rowspan=10)  # command=done)
b2 = Button(root, text="Enter", width=10, command=give_values).grid(row=1, column=10, rowspan=10)  # command=enter())
 
root.mainloop()
Reply


Messages In This Thread
Python Newbie - by MartyH - May-11-2020, 11:41 PM
RE: Python Newbie - by MartyH - May-12-2020, 02:02 PM
RE: Python Newbie - by deanhystad - May-12-2020, 02:39 PM
RE: Python Newbie - by MartyH - May-13-2020, 04:53 PM
RE: Python Newbie - by buran - May-13-2020, 05:15 PM
RE: Python Newbie - by deanhystad - May-13-2020, 05:43 PM
RE: Python Newbie - by MartyH - May-13-2020, 07:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] newbie with python and tkinter pat 8 5,740 Jun-26-2018, 07:43 PM
Last Post: pat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020