Reputation: 1
New to Python but have been having issues with the combobox.
I have checked the forums but have not seen an answer to stop any of the errors I am getting with the combobox. I receive the following error:
"menuItem1 = self.cmbBxMen1.get() AttributeError: 'NoneType' object has no attribute 'get'"
root and frame are set the class is Application and the method causing the error is in the same class as the call and placement of the widget method, but in a different method. The button object's command property is set to use the Add_To_Menu method that gets the value selected in the combobox. The code is as follows:
def __init__(self, master):
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
data = Application.data
self.cmbBxMen1 = Combobox(self, values = data, width = 60).grid(row=0, column=1, padx = 4, pady = 20)
self.btnAdMen = Button(self, text = "Add to Menu", command = self.Add_To_Menu).grid(row=0, column=9, pady = 20, sticky = W)
def Add_To_Menu(self):
menuItem1 = self.cmbBxMen1.get()
Can someone please tell me what I am doing wrong to cause this error?
Upvotes: 0
Views: 1471
Reputation: 4206
The problem is that widget.grid()
is in fact not returning the widget after putting it to the layout. It returns None
. You should call .grid()
separately and same with the button.
self.cmbBxMen1 = Combobox(self, values = data, width = 60)
self.cmbBxMen1.grid(row=0, column=1, padx = 4, pady = 20)
Upvotes: 1