Reputation: 7
I am quite new to using Tkinter in python and I intended to create a table generation function within my software solution using it and what I'm finding issue is finding a way to call on and get the data within the table of entries to put inside a list and then use matplotlib to generate a graph from the table. So far I've tried using a for loop that would iterate throughout the same variable I used to generate my table in order to get the data from the entries, but that would only give the value of the bottom right entry in the table and nothing else. As well, I've only seen guides of a similar topic only show how to display data within the entries rather than get them.
import tkinter as tk
import matplotlib.pyplot as plt
graphinput = tk.Tk()
def opentable():
global total_rows
global total_columns
total_rows = int(yaxis.get())
total_columns = int(xaxis.get())
table = tk.Toplevel(graphinput)
def tcompile():
masterlines = []
for entries in my_entries:
print(cell.get())
masterlines.append(int(cell.get()))
plt.plot(masterlines)
plt.show()
my_entries = []
for i in range(total_rows):
for j in range(total_columns):
cell = tk.Entry(table,width=20,font=('Agency FB',15))
cell.grid(row=i,column=j)
my_entries.append(cell)
tblframe = tk.Frame(table,bd=4)
tblframe.grid(row=i+1,column=j)
compbtn = tk.Button(tblframe,font=("Agency FB",20),text="Compile",command=tcompile)
compbtn.grid(row=0,column=0)
tablegrid = tk.Frame(graphinput,bd=4)
tablegrid.pack()
xlabel = tk.Label(tablegrid,text="Column Entry")
xlabel.grid(row=0,column=0)
ylabel = tk.Label(tablegrid,text="Row Entry")
ylabel.grid(row=0,column=1)
xaxis = tk.Entry(tablegrid)
xaxis.grid(row=1,column=0)
yaxis = tk.Entry(tablegrid)
yaxis.grid(row=1,column=1)
framebtn = tk.Button(tablegrid,text="Create",command=opentable)
framebtn.grid(row=3,column=0)
graphinput.mainloop()
Upvotes: 0
Views: 1113
Reputation: 7680
Right now inside tcompile
cell refers to the last entry that was created. When you are iterating over the list of entries (my_entries
) you save each entry in a variable called entries
not cell
. So I suggest you change the for entries in my_entries
=> for cell in my_entries
. That way each entry will be saved inside cell
so you can call cell.get()
.
Upvotes: 1