how can i make the user input become a variable and then have that variable be used in a later function? this is my code: : I can't figure out what im doing wrong, i wanted to make a program that allowed the user to pick a stock ticker and a couple of other inputs, and then get real time data that immediately went back into the program and would display the stock info and stuff. theres a lot of code there, i wanted to make a stock program that allowed the user to pick a stock, pick a start and end date, and see some basic stock info from those dates. that code isself works, but ive been struggling with getting you to be able to use a gui to provide inputs into the stock program.



    from tkinter import *
    #import tkinter
    from tkinter import ttk
    import random
    import random
    import datetime as dt
    import matplotlib.pyplot as plt
    from matplotlib import style
    import pandas as pd
    import pandas_datareader.data as web
    from optparse import OptionParser
    
    compname = 'Company Name'
    tckersymbl = 'Ticker Symbol'
    strtdte = 'Start Date (y, m, d)'
    numbday = 'Number of Days'
    
    
    #fields = 'Company Name', 'Ticker Symbol', 'Start Date (y, m, d)', 'Number of Days'
    
    def fetch(entries):
       for entry in entries:
          field = entry[0]
          text  = entry[1].get()
          companyname = entry[0]
          print('%s: "%s"' % (field, text))
                
    
    def makeform(root, tckersymbl):
       entries = []
       for field in compname:
          companyname = entry[0]
          row = Frame(root)
          lab = Label(row, width=15, text=field, anchor='w')
          ent = Entry(row)
          row.pack(side=TOP, fill=X, padx=5, pady=5)
          lab.pack(side=LEFT)
          ent.pack(side=RIGHT, expand=YES)
          entries.append((field, ent))
       return entries
    
    def fetch1(entries):
       for entry in entries:
          field1 = entry[2]
          text1  = entry[3].get()
          ticker = entry[2]
          print('%s: "%s"' % (field1, text1)) 
    
    def makeform1(root, tckersymbl):
       entries = []
       for field1 in tckersymbl:
          ticker = entry[2]
          row = Frame(root)
          lab = Label(row, width=15, text=field1, anchor='w')
          ent = Entry(row)
          row.pack(side=TOP, fill=X, padx=5, pady=5)
          lab.pack(side=LEFT)
          ent.pack(side=RIGHT, expand=YES)
          entries.append((field1, ent))
       return entries
    
    def fetch2(entries):
       for entry in entries:
          field2 = entry[4]
          text2  = entry[5].get()
          startday = entry[4]
          startday1 = startday.int()
          print('%s: "%s"' % (field2, text2)) 
    
    def makeform2(root, strtdte):
       entries = []
       for field2 in strtdte:
          startday = entry[4]
          startday1 = startday.int()
          row = Frame(root)
          lab = Label(row, width=15, text=field2, anchor='w')
          ent = Entry(row)
          row.pack(side=TOP, fill=X, padx=5, pady=5)
          lab.pack(side=LEFT)
          ent.pack(side=RIGHT, expand=YES)
          entries.append((field2, ent))
       return entries
    
    def fetch3(entries):
       for entry in entries:
          field3 = entry[6]
          text3  = entry[7].get()
          numbdays = entry[6]
          print('%s: "%s"' % (field3, text3)) 
    
    def makeform3(root, numbday):
       entries = []
       for field3 in numbday:
          numbdays = entry[6]
          row = Frame(root)
          lab = Label(row, width=15, text=field3, anchor='w')
          ent = Entry(row)
          row.pack(side=TOP, fill=X, padx=5, pady=5)
          lab.pack(side=LEFT)
          ent.pack(side=RIGHT, expand=YES)
          entries.append((field3, ent))
       return entries
    
    #companyname = entry[0]
    #ticker = entry[2]
    #startday = entry[4]
    #startday1 = startday.int()
    #numbdays = entry[6]
    
    print(companyname)
    style.use('ggplot')
    
    start = dt.datetime(startday1)
    end = dt.datetime.now()
    
    df = web.DataReader(ticker, 'iex', start, end)
    df.reset_index(inplace=True)
    
    print(df.head(numbdays)) #change value to change number of days you get. default is five
    
    
    if __name__ == '__main__':
       root = Tk()
       root.geometry("350x175")
       ents = makeform(root, compname, tckersymbl, strtdte, numbday)
       root.bind('<Return>', (lambda event, e=ents: fetch(e)))   
       b1 = Button(root, text='Show',
              command=(lambda e=ents: fetch(e)))
       b1.pack(side=LEFT, padx=5, pady=5)
       b2 = Button(root, text='Quit', command=root.quit)
       b2.pack(side=LEFT, padx=5, pady=5)
    
       root.mainloop()
    
    
    
    
       
    #compname = 'Company Name'
    #tckersymbl = 'Ticker Symbol'
    #strtdte = 'Start Date (y, m, d)'
    #numbday = 'Number of Days'

