Python Forum
[Tkinter] Entry returns NONE
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Entry returns NONE
#1
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
Reply


Messages In This Thread
Entry returns NONE - by mollerpunker - Dec-03-2020, 07:36 PM
RE: Entry returns NONE - by Gribouillis - Dec-04-2020, 07:37 AM
RE: Entry returns NONE - by DT2000 - Dec-06-2020, 06:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Test program returns int (I want int) and real one returns tuple (not wanted) chesschaser 16 5,166 Mar-26-2020, 11:26 AM
Last Post: chesschaser
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,483 Jan-23-2020, 09:00 PM
Last Post: HBH
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 3,511 Mar-18-2019, 05:36 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020