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
#4
When you have multiple things you need to use a container of some sort. Python uses dictionaries to hold a collection of things that can be referenced by a key. Python also has lists and tuples which use an index instead of a key. A tuple is immutable (cannot be changed), so that is not a good choice for containing items where the number of items can grow. That leaves a list.
import tkinter as tk
 
root = tk.Tk() 
menu = tk.Menu(root)
root.config(menu=menu)
entry_list = []    # List to hold all my Entry's
 
def addentry():
    entry = tk.Entry(root)
    entry.pack()
    entry_list.append(entry)
 
def printa():
    for entry in entry_list:
        print(entry.get())
     
addentry()

confirmbutton = tk.Button(root, text='Confirm', width=25, command=printa)
confirmbutton.pack()
 
confirmbutton2 = tk.Button(root, text='Add', width=25, command=addentry)
confirmbutton2.pack()
 
tk.mainloop()
The program is a little wonky in that the first entry appears above the Add and Confirm button and additional entries appear below. In a GUI it would be more common to have an entry field, an add button, and another widget that displays all the values that were entered.

Going back to your basketball lineup program, I can see it having an entry for the player name and a list box for the position, and an additional widget that displays the current lineup. The program would have an add button for adding a player using info from the player name entry and position listbox as well as a bench button for removing a player selected in the lineup widget.
Reply


Messages In This Thread
RE: Print Values from a Sequence of Entries / ComboBoxes - by deanhystad - Mar-28-2020, 08:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get tkinter database aware cascading comboboxes to update properly dford 6 3,704 Jan-11-2022, 08:37 PM
Last Post: deanhystad
  Linking Comboboxes MrP 24 7,368 Feb-03-2021, 10:59 PM
Last Post: MrP
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,940 Jul-29-2020, 07:13 PM
Last Post: deanhystad
  [PyQt] making dependant comboBoxes Hitsugaya 3 5,055 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