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
#1
Hi - I want to build a program to add a basketball lineup.

Ideally I want the output to be (as an example):
Center, John
Point Guard, Jack
Shooting Guard, James

This would depend on how many values you add and what you type for the name. I am struggling to pull these values that are entered. I am not getting an error - just not getting the results I am looking for. For example, instead of "Point Guard", it says "<tkinter.ttk.Combobox object .!combobox2>". I am also not returning a value for the Entry fields. Any help would be greatly appreciated!!



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

root = Tk() 
menu = Menu(root)
root.config(menu=menu)

combovalues = ['Center' , 'Point Guard' , 'Shooting Guard' , 'Power Forward' , 'Small Forward' ]
startinglineup = []
entry_values = []


root.counter = 2
my_lineup = []
string_var = tk.StringVar()
entry_values.append(string_var)

def addlineup():

    Label(root, text='Lineup Name').grid(row=0) 
    e1 = Entry(root) 
    e1.grid(row=0, column=1)
    combobox = ttk.Combobox(root, values=combovalues)
    combobox.grid(column=0, row=1)
    e2 = Entry(root)
    e2.grid(row=1, column=1)
    addbutton = tk.Button(root, text='Add', width=25, command=add) 
    addbutton.grid(column=0, row=14)
    confirmbutton = tk.Button(root, text='Confirm', width=25, command=save)
    confirmbutton.grid(column=0, row=15)


def save():
    number = root.counter
    print(my_lineup)


def add():
    root.counter += 1
    combobox = ttk.Combobox(root, values=combovalues)
    combobox.grid(column=0, row=root.counter)
    entry = Entry(root) 
    entry.grid(row=root.counter, column=1)
    for stringvar in entry_values:
        text = string_var.get()
        if text:
            my_lineup.append(text)
    my_lineup.append([text, combobox])
    


# --- main menu ---
filemenu = Menu(menu) 
menu.add_cascade(label='File', menu=filemenu) 


# --- lineupss ----
lineupmenu = Menu(menu) 
menu.add_cascade(label='Lineups', menu=lineupmenu) 
lineupmenu.add_command(label='Add Lineup', command=addlineup)
lineupmenu.add_command(label='View Lineups')


mainloop() 
Output:
[['', <tkinter.ttk.Combobox object .!combobox2>], ['', <tkinter.ttk.Combobox object .!combobox3>]]
Reply


Messages In This Thread
Print Values from a Sequence of Entries / ComboBoxes - by MC2020 - Mar-26-2020, 01:07 AM

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