-1

I am getting this error when i am running my code of SIMPLE GUI

AttributeError: 'NoneType' object has no attribute 'get'

The gui is pretty simple in itself it is mostly about creating a software login function with serial key.I saw some tutorials online and created this example which when i run i get a error.How can i solve this ?

from tkinter import  *
root1 = Tk()
root1.geometry("700x330+350+300")
key = "Agcy5x7kZe"
frame = LabelFrame(root1)

def Submitcommand():
    a = entry.get()
    b = serialentry.get()
    print(a)# To check
    print(b)# To check


photo = PhotoImage(file = 'gil.png')
photo1 = Label(frame , image = photo).grid(row = 0 , column = 0 , columnspan = 2 , pady = (0 , 20))

username = Label(frame, text = "Username :" , font = "helvetica 30 bold").grid(row = 1 , column = 0)
entry = Entry(frame, bd = 5 , font = "Lucida 30 bold" , width = 25).grid(row = 1 , column = 1)


label = Label(frame, text = "Serial Key : " , font = "helvetica 30 bold").grid(row = 2 , column = 0)
serialentry = Entry(frame, bd = 5 , font = "Lucida 30 bold" , width = 25).grid(row = 2 , column = 1)

submit = Button(frame , text = "Login" , height = 2 , width = 10 , command = Submitcommand).grid(row = 3 , column = 1 , columnspan = 2 , pady = (0 , 20))
frame.place(relx = 0.5 , rely = 0.5 , anchor = CENTER)


root1.mainloop()
Anush Kamble
  • 51
  • 11
  • You seem to have posted more code than what would be reasonable for your issue. Please read [ask] and how to make a [mre]; providing a MRE helps users answer your question and future users relate to your issue. – rizerphe May 09 '20 at 15:22
  • Can you elaborate on how your code "doesn't work"? What were you expecting, and what actually happened? If you got an exception/error, post the line it occurred on and the exception/error details which can be done with a [mre]. Please [edit] your question to add these details into it or we may not be able to help. – rizerphe May 09 '20 at 15:23
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](//creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](//meta.stackexchange.com/q/5221) – Sabito stands with Ukraine Jan 31 '21 at 07:26
  • 1
    I have edited my question to make others helpful.By adding more details into the question. – Anush Kamble Apr 01 '21 at 16:03

1 Answers1

1

You have to first create the widget, and only then place etc. it. You see, Entry() returns an entry object, so once you do e = Entry(), e is an object. That object has an place method, so once you run e.place() it then places it. The problem is that

a = Entry().place()

and

e = Entry()
a = e.place()

produce the same a, but you are not interested in that, you need e. Here is your code fixed:

from tkinter import  *
root1 = Tk()
root1.geometry("700x330+350+300")
key = "Agcy5x7kZe"
frame = LabelFrame(root1)

def Submitcommand():
    a = entry.get()
    b = serialentry.get()
    print(a)# To check
    print(b)# To check


photo = PhotoImage(file = '/home/pi/2020-05-02-143258_1920x1080_scrot.png')
photo1 = Label(frame , image = photo)
photo1.grid(row = 0 , column = 0 , columnspan = 2 , pady = (0 , 20))

username = Label(frame, text = "Username :" , font = "helvetica 30 bold")
username.grid(row = 1 , column = 0)
entry = Entry(frame, bd = 5 , font = "Lucida 30 bold" , width = 25)
entry.grid(row = 1 , column = 1)


label = Label(frame, text = "Serial Key : " , font = "helvetica 30 bold")
label.grid(row = 2 , column = 0)
serialentry = Entry(frame, bd = 5 , font = "Lucida 30 bold" , width = 25)
serialentry.grid(row = 2 , column = 1)

submit = Button(frame , text = "Login" , height = 2 , width = 10 , command = Submitcommand)
submit.grid(row = 3 , column = 1 , columnspan = 2 , pady = (0 , 20))
frame.place(relx = 0.5 , rely = 0.5 , anchor = CENTER)


root1.mainloop()

Hope that's helpful!

rizerphe
  • 1,340
  • 1
  • 14
  • 24