Python Forum

Full Version: Entry returns NONE
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I'm a beginner in programming with PY and started to build an GUI. Got stuck with retrieving the value of the Entry. While running the GUI the choosen location in the combobox return the values of the Entry fields. The next step is read the values to use it to calculate the directions in another PY file. For debugging i want to print the values of the Entries to determine if i get the right values. What do I wrong?

from tkinter import *
from tkinter import messagebox
from tkinter.ttk import *

window = Tk()
window.title('Declaratie dienstreis')
window.configure(background='white')
window.geometry('500x500')

locaties_dict = {
    'Vlissingen': {
        'vestiging': 'Vlissingen',
        'straat': 'Boulevard Bankert',
        'nr': '156'
    },
    'Middelburg': {
        'vestiging': 'Middelburg',
        'straat': 'Buitenruststraat',
        'nr': '16'
    },
    'Goes': {
        'vestiging': 'Goes',
        'straat': 'Zonnebloemstraat',
        'nr': '16'
    },
    'Zierikzee': {
        'vestiging': 'Zierikzee',
        'straat': 'Koning Gustaafweg',
        'nr': '2'
    },
    'Overig': {
        'vestiging': '',
        'straat': '',
        'nr': ''
    },
}

straat1 = StringVar()
nummer1 = StringVar()
plaats1 = StringVar()

straat2 = StringVar()
nummer2 = StringVar()
plaats2 = StringVar()

def handle_select_start(event):
    straat1.set(locaties_dict[combo_start.get()]['straat'])
    nummer1.set(locaties_dict[combo_start.get()]['nr'])
    plaats1.set(locaties_dict[combo_start.get()]['vestiging'])

def handle_select_eind(event):
    straat2.set(locaties_dict[combo_eind.get()]['straat'])
    nummer2.set(locaties_dict[combo_eind.get()]['nr'])
    plaats2.set(locaties_dict[combo_eind.get()]['vestiging'])

beginlocatie = Label(window, text='Beginlocatie', background='white', font=('Arial Bold', 14))\
    .grid(row=0, column=0, sticky=W)

lbl_vestiging_start = Label(window, text='Vestiging', background='white', font=('Arial', 10))\
    .grid(row=1, column=0, sticky=W)
combo_start = Combobox(window)
combo_start['values'] = list(locaties_dict.keys())
combo_start.bind('<<ComboboxSelected>>', handle_select_start)
combo_start.grid(row=1, column=2)

lbl_straat_start = Label(window, text='Straat', background='white', font=('Arial', 10)).grid(row=2, column=0, sticky=W)
lbl_nummer_start = Label(window, text='Huisnummer', background='white', font=('Arial', 10)).grid(row=3, column=0, sticky=W)
lbl_plaats_start = Label(window, text='Plaats', background='white', font=('Arial', 10)).grid(row=4, column=0, sticky=W)
straat_start = Entry(window, width=20, textvariable=straat1).grid(row=2, column=2, sticky=W)
nummer_start = Entry(window, width=20, textvariable=nummer1).grid(row=3, column=2, sticky=W)
plaats_start = Entry(window, width=20, textvariable=plaats1).grid(row=4, column=2, sticky=W)

eindlocatie = Label(window, text='Eindlocatie', background='white', font=('Arial Bold', 14))\
    .grid(row=7, column=0, sticky=W)

lbl_vestiging_eind = Label(window, text='Vestiging', background='white', font=('Arial', 10))\
  .grid(row=8, column=0, sticky=W)
combo_eind = Combobox(window)
combo_eind['values'] = list(locaties_dict.keys())
combo_eind.bind('<<ComboboxSelected>>', handle_select_eind)
combo_eind.grid(row=8, column=2)

lbl_straat_eind = Label(window, text='Straat', background='white', font=('Arial', 10)).grid(row=9, column=0, sticky=W)
lbl_nummer_eind = Label(window, text='Huisnummer', background='white', font=('Arial', 10)).grid(row=10, column=0, sticky=W)
lbl_plaats_eind = Label(window, text='Plaats', background='white', font=('Arial', 10)).grid(row=11, column=0, sticky=W)

straat_eind = Entry(window, width=20, textvariable=straat2).grid(row=9, column=2, sticky=W)
nummer_eind = Entry(window, width=20, textvariable=nummer2).grid(row=10, column=2, sticky=W)
plaats_eind = Entry(window, width=20, textvariable=plaats2).grid(row=11, column=2, sticky=W)


def send_addresses():
    messagebox.showinfo( "", "Adressen zijn verstuurt, wacht op aantal km")
    print(straat_eind)

B = Button(text ="Haal aantal km op", command = send_addresses).grid(row=11, column=4, sticky=W)


window.mainloop()
The error i get is
Error:
NONE
(untested) I think instead of print(straat_eind) it should be print(straat2.get())
If you change your print line to
print(straat2.get())
you will get the Straat2, which is already known.

I am guessing you are trying to have a distance calculator to determine the distance between the 2 location addresses selected?
If this is true then you need a database with the distance information so you can query and populate your widget with that data otherwise you are only calling the data that you already have assigned to the widget, straat2.

No actual KM data is available to calculate the distance of travel between a users 2 city locations.