Mar-28-2020, 04:34 PM
Thank you very much for the response. I am new to learning this and it can be difficult to find exactly what I am looking for online. Your reply is incredibly helpful.
I am trying to make a simpler program now to understand some of the basics before I move on to anything more advanced. For example, below I have rebuilt a simple program. I am trying to print a list of all of the values in each entry. The amount of entrys is variable based on how many the user decides to add. I am having trouble figuring out how to reference the added entrys. They would all have the name 'entry 2'. Is there a loop that needs to be added to append a blank variable for each entry? I have tried a few different ways and nothing has worked for me.
If I can wrap my head around how this works, I think it would help me tremendously moving forward.
This is the error I am getting:
I am trying to make a simpler program now to understand some of the basics before I move on to anything more advanced. For example, below I have rebuilt a simple program. I am trying to print a list of all of the values in each entry. The amount of entrys is variable based on how many the user decides to add. I am having trouble figuring out how to reference the added entrys. They would all have the name 'entry 2'. Is there a loop that needs to be added to append a blank variable for each entry? I have tried a few different ways and nothing has worked for me.
If I can wrap my head around how this works, I think it would help me tremendously moving forward.
This is the error I am getting:
Error:result2 = entry2.get()
NameError: name 'entry2' is not defined
import tkinter as tk from tkinter import * from tkinter import ttk root = Tk() menu = Menu(root) root.config(menu=menu) string_var = tk.StringVar() entry = tk.Entry(root, textvariable=string_var) entry.pack() def addentry(): entry2 = tk.Entry(root) entry2.pack() def printa(): result = entry.get() result2 = entry2.get() print(result) print(result2) confirmbutton = tk.Button(root, text='Confirm', width=25, command=printa) confirmbutton.pack() confirmbutton2 = tk.Button(root, text='Add', width=25, command=addentry) confirmbutton2.pack() mainloop()Ideally if I had 5 entries with a, b, c, d, e typed into each respective entry, the print(results) line would return 'a, b, c, d, e'.