I am working on a program for class and am having trouble with user input. This is what I have, can someone help me figure out what I am doing wrong? All of the buttons work (this is only part of the code), but the user input area for menu3A doesn't seem to accept the user input. It tells me that variable1 is undefined.
Module 1:
from tkinter import *
from tkinter import ttk
import functions
import finance
def donothing():
filewin = Toplevel(root)
button = Button(filewin, text="Do nothing button")
button.pack()
# Menu 1 - opening menu
def menu1():
filewin = Toplevel(root)
button1 = Button(filewin, text="Use your own CSV Data", command = menu3A)
button1.pack()
button2 = Button(filewin, text="Use Data Included in program", command = menu2)
button2.pack()
# Menu 2 - Menu 2 is only used if Data from Menu1 specifies program data used
def menu2():
FileName = ''
filewin = Toplevel(root)
Label(root, text="Enter the ticker symbol for your chosen stock or type Back to go back: ").grid(row=0, sticky=W) #label
Entry(root, textvariable = FileName).grid(row=0, column=1, sticky=E) #entry textbox
WSignUp = Button(root, text="Enter", command=functions.getvalue2).grid(row=3, column=0, sticky=W) #button
# Menu 3A - loading CSV File - only used if Data from Menu1 specifies user wishes to load CSV
variable1=StringVar()
ttk.Entry(root, width=7, textvariable=variable1).grid(column=2, row=1)
ttk.Label(root, text="Enter Filename: ").grid(column=1, row=1)
ttk.Button(root, text="Enter", command=functions.getvalue1()).grid(column=2, row=13)
root = Tk()
root.title('Rachels Stocks Python Program')
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New", command=menu1)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Undo", command=donothing)
editmenu.add_separator()
editmenu.add_command(label="Cut", command=donothing)
editmenu.add_command(label="Copy", command=donothing)
editmenu.add_command(label="Paste", command=donothing)
editmenu.add_command(label="Delete", command=donothing)
editmenu.add_command(label="Select All", command=donothing)
menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help Index", command=donothing)
helpmenu.add_command(label="About...", command=donothing)
menubar.add_cascade(label="Help", menu=helpmenu)
root.config(menu=menubar)
root.mainloop()
Module 2:
import finance
#Function that menu 3A uses to print and use CSV filename
def getvalue1():
FileName = variable1.get()
print(f"Filename entered is: {FileName}")
finance.CSV_Finance_Tool(FileName)
If I try to do this:
WSignUp = Button(root, text="Enter", command=functions.getvalue2(variable1)).grid(row=3, column=0, sticky=W) #button
Then it automatically seems to pass the empty variable onto CSV_Finance_Tool and I am getting the file exception response of file not found. It doesn't wait for the user input.