Mar-26-2020, 01:07 AM
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!!
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>]]
