Python Forum
Print Values from a Sequence of Entries / ComboBoxes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Values from a Sequence of Entries / ComboBoxes
#3
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:

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'.
Reply


Messages In This Thread
RE: Print Values from a Sequence of Entries / ComboBoxes - by MC2020 - Mar-28-2020, 04:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get tkinter database aware cascading comboboxes to update properly dford 6 3,706 Jan-11-2022, 08:37 PM
Last Post: deanhystad
  Linking Comboboxes MrP 24 7,372 Feb-03-2021, 10:59 PM
Last Post: MrP
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,945 Jul-29-2020, 07:13 PM
Last Post: deanhystad
  [PyQt] making dependant comboBoxes Hitsugaya 3 5,057 May-23-2019, 06:05 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

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