So as the title suggests, I'm having trouble passing in 2 arguments to a function I want to call when an option menu is changed.
Here is the code below:
OPTIONS = [
"Fire",
"Ice",
"Storm",
"Life",
"Myth",
"Death",
"Balance"
]
var = StringVar(frame)
var.set("Select School") # initial value
option = OptionMenu(frame, var,*OPTIONS,command= lambda frame,var : changeSchool(frame,var))
option.grid(row=0,column=0,sticky=(N,W))
I've done some research and I think I've done everything correctly but I get the following error when I select an option in the option menu:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Gunner\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "C:\Users\Gunner\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 3287, in __call__
self.__callback(self.__value, *args)
TypeError: <lambda>() missing 1 required positional argument: 'var'
I thought I've passed in var into the changeSchool function.
I appreciate any help!
EDIT: Here's my changeSchool function for those who wish to see it:
def changeSchool(frame,school):
print (school)
WizTool.schoolType = school
self.initBT(frame,WizTool.schoolType)
print (WizTool.schoolType)
EDIT: Here's the entire program (showing how frame is not in scope)
from tkinter import *
from tkinter import ttk
from functools import partial
import webbrowser
import pprint
class WizTool:
schoolType = "Fire"
#initialize the GUI
def __init__(self, master):
content = ttk.Frame(master, padding=(3,3,12,12))
frame = ttk.LabelFrame(content, borderwidth=5, relief="sunken", width=400, height=400,padding=(3,3,12,12),text = "Blade Tracker")
content.grid(column=0,row=0,sticky=(N,S,E,W))
frame.grid(column=0, row=0, columnspan=4, sticky=(N, S, E, W))
self.master = master
self.initUI(content)
self.initBT(frame,WizTool.schoolType)
def initUI(self,frame):
self.master.title("Bootstrapper")
def changeSchool(frame,school):
print (school)
WizTool.schoolType = school
self.initBT(frame,WizTool.schoolType)
print (WizTool.schoolType)
def initBT(self,frame,mySchool):
#option menu for selecting school
OPTIONS = [
"Fire",
"Ice",
"Storm",
"Life",
"Myth",
"Death",
"Balance"
]
var = StringVar(frame)
var.set("Select School") # initial value
option = OptionMenu(frame, var,*OPTIONS,command= lambda frame,var : changeSchool(frame,var))
option.grid(row=0,column=0,sticky=(N,W))
def main():
root = Tk()
root.geometry("800x500+300+300")
app = WizTool(root)
root.mainloop()
main()