0

I made a couple of combo-boxes, where the User can choose between pre-defined settings:

# create comboboxes for settings
combobox_sensortype = ttk.Combobox(root, values=('RGB','MS'), state='readonly').grid(row=3,column=2)
combobox_dem_dop = ttk.Combobox(root, values=('DEM','DOP'), state='readonly').grid(row=4,column=2)
combobox_sensortype_def = ttk.Combobox(root, values=('RGB_HZ','RGB_MR','MS_HZ','MS_MR'), state='readonly').grid(row=5,column=2)
combobox_run_SAGA_bat = ttk.Combobox(root, values=('Yes','No'), state='readonly').grid(row=6,column=2)
   
# getters for extracting user input from comboboxes
sensortype = combobox_sensortype.get()
demdop = combobox_dem_dop.get()
sensortype_def = combobox_sensortype_def.get()
run_SAGA_bat = combobox_run_SAGA_bat.get()

Unfortunately, I get this: AttributeError: 'NoneType' object has no attribute 'get'

Whats the issue here? I really hope someone can help.

Tybald
  • 167
  • 1
  • 1
  • 12

1 Answers1

1

This is because you called the method .grid(row=3,column=2). This doesn't return anything, thus the variable's value was set to None. To get your result, put them in separate lines. So you should define the Combobox, then grid it.

Solution:

import tkinter.ttk as ttk
from tkinter import *

root = Tk()

# create comboboxes for settings
combobox_sensortype = ttk.Combobox(root, values=('RGB', 'MS'), state='readonly')  # define the combobox
combobox_sensortype.grid(row=3, column=2)  # grid it!

combobox_dem_dop = ttk.Combobox(root, values=('DEM', 'DOP'), state='readonly')
combobox_dem_dop.grid(row=4, column=2)

combobox_sensortype_def = ttk.Combobox(root, values=('RGB_HZ', 'RGB_MR', 'MS_HZ', 'MS_MR'), state='readonly')
combobox_sensortype_def.grid(row=5, column=2)

combobox_run_SAGA_bat = ttk.Combobox(root, values=('Yes', 'No'), state='readonly')
combobox_run_SAGA_bat.grid(row=6, column=2)

# getters for extracting user input from comboboxes
sensortype = combobox_sensortype.get()
demdop = combobox_dem_dop.get()
sensortype_def = combobox_sensortype_def.get()
run_SAGA_bat = combobox_run_SAGA_bat.get()


root.mainloop()
Tkinter Lover
  • 835
  • 3
  • 19