0

So here I wanted to use the Django OR with Tkinter for a school project. I can ACCESS the database from a tkinter window, it is not the problem. When I want to retrieve the value of an Entry, it puts me 'NoneType' object Has No attribute 'get'.

import os
import sys

sys.path.append(os.path.abspath(os.path.dirname(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'Journal.settings'

from tkinter import *
from blog.models import *


def connexion():
    try:
        user = User.objects.get(username=userEntry.get())
        if user.check_password(pwdEntry.get()) == True:
            windows.messagebox.showinfo('Connexion', 'You are connected')
        else:
            windows.messagebox.showwarning('Warning', "The password is invalid")
    except User.DoesNotExist:
        windows.messagebox.showwarning('Warning', "The username does not exist")


windows = Tk()

Connexion = Frame(windows, bg="white")
Connexion.pack(side=TOP, padx=5, pady=5)

Bouton = Frame(windows, bg="white")
Bouton.pack(side=BOTTOM, padx=5, pady=5)

userLabel = Label(Connexion, text="Username:").pack(padx=5, pady=5)
userEntry = Entry(Connexion, width=15).pack()

pwdLabel = Label(Connexion, text="Password:").pack(padx=5, pady=5)
pwdEntry = Entry(Connexion, width=15, show="*").pack()


quitBouton = Button(Bouton, text="Fermer", command=windows.quit).pack(side=RIGHT, padx=5, pady=5)
connexionBouton = Button(Bouton, text="Connexion", command=connexion).pack(side=LEFT, padx=5, pady=5)

windows.mainloop()

L'erreur

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1533, in __call__
    return self.func(*args)
  File "/Users/saikouah/Documents/Journal/Tkinter Interface/interface.py", line 13, in connexion
    user = User.objects.get(username=userEntry.get())
AttributeError: 'NoneType' object has no attribute 'get'
bluebeel
  • 83
  • 3
  • 9
  • It's interesting how you have make this works, but I don't know if it's a good idea to the future, BTW have you read about [PonyORM](https://ponyorm.com/)? – Gocht Nov 04 '15 at 16:46
  • Yeah it's not bad but I would therefore create the models for the ORM. While here I have my models factual and functional. I just do not understand why I have this error – bluebeel Nov 04 '15 at 16:58
  • What is userEntry? is it a queryset? is a dict? Where are you using conexion method? – Gocht Nov 04 '15 at 17:00
  • userEntry is a variable where I store the Entry widget is an Input. Normally the get () method after the doc is supposed to return the value of this entry. Connection is a frame that separates my elements to the layout. userEntry as pwdEntry is part of the frame. – bluebeel Nov 04 '15 at 17:03
  • Take a look into conexion method, userEntry have not been defined there, or passes as a param – Gocht Nov 04 '15 at 17:06
  • First thing I'd do is separate the two `get()` methods into two separate lines, so you know exactly which statement causes the error. – knbk Nov 04 '15 at 17:31

0 Answers0