I am attemting to pass the variable dataLength into a label in the third of my Tkinter windows. the goal is to end up having a label that says "the length of your data set is:" then have the value of the dataLength variable after "is:". here is all my current code:
# imports
from statistics import mode
from statistics import median
from tkinter import *
# The Code For The GUI
data = ''
# function that starts the third window
def start_w_3():
root3 = Tk()
root3.geometry("400x300")
app3 = Window3(root3)
root3.mainloop()
# function that starts the second window
def start_w_2():
root2 = Tk()
root2.geometry("400x300")
app2 = Window2(root2)
root2.mainloop()
# making the third window
class Window3(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window3()
def init_window3(self):
self.master.title("data analyzer to go")
self.pack(fill=BOTH, expand=1)
lengthL = Label(self, text="The length of your data set is: ")
lengthL.pack()
# making the second window
class Window2(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window2()
def init_window2(self):
self.master.title("Data Analyzer To Go")
self.pack(fill=BOTH, expand=1)
viewButton = Button(self, text="View Results", command=start_w_3)
viewButton.place(x=163, y=125)
# making the first window
class Window1(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window1()
def init_window1(self):
self.master.title("Data Analyzer To Go")
self.pack(fill=BOTH, expand=1)
analyzeButton = Button(self, text="Analyze Data", command=lambda:[self.getData(), start_w_2()])
dataPrompt = Label(self, text="Please enter your data")
global data
self.var=StringVar(self)
e = Entry(self, textvariable=self.var)
analyzeButton.place(x=150, y=150)
e.place(x=125, y=125)
dataPrompt.place(x=125, y=100)
def getData(self):
global data
data=self.var.get()
root1 = Tk()
root1.geometry("400x300")
app1 = Window1(root1)
root1.mainloop()
# variables
data = [int(n) for n in data.split(' ')]
data.sort()
dataLength = len(data)
dataInt = list(map(int, data))
dataTotal = sum(dataInt)
dataMean = dataTotal / dataLength
highNumber = max(data)
lowNumber = min(data)
dataRange = highNumber - lowNumber
# telling length of data
#print("there is this many numbers in your data set: ")
print(dataLength, "\n")
# data sorted
print("your data in ascending order is: ")
print(data, "\n")
# total of data
print("the total of your data is: ")
print(dataTotal, "\n")
# mean of data
print("the mean of your data is: ")
print(dataMean, "\n")
# code to find and display data mode
try:
dataMode = mode(data)
print("the mode of your data is: ")
print(dataMode, "\n")
except:
StatisticsError:\
print("no mode found. \n")
# code to find and display median of data.
try:
dataMedian = median(data)
print("the median of your data is: ")
print(dataMedian, "\n")
except:
StatisticsError:\
print("no median found. \n")
# display the range of the data
print("the range of your data set is: ")
print(dataRange)
Just a review of the question, I am trying to have the dataLength variable passed into a label in the third window so that the third window contains: "The length of you data set is: " then the value of dataLength. any help is appreciated, Thanks!