-2

programm is working perfectly before defining the function problem is that it is not getting the value from the user input and showing it to me and then error is coming too.

from tkinter import *
from tkinter import ttk



root = Tk()
root.title("Social Network - Login")

frame = ttk.Frame(root) #define new frame
frame.grid(row=2,column=1)
frame.config(height=200, width=200, relief=RIDGE, padding=(10,10))


l1 = ttk.Label(frame, text="User name").grid(row=0, column=0)

etUserName = ttk.Entry(frame, width=20).grid(row=0, column=1)

l2 = ttk.Label(frame, text="Password").grid(row=1,column=0)

etpassword = ttk.Entry(frame, width=20, show="*").grid(row=1, column=1)

buLogin = ttk.Button(frame,text="Login").grid(row=2,column=1)

def BuClick():
    print("Username: {},Password: {}".format(etUserName.get(),etpassword.get()))


buLogin.config(command=BuClick)

root.mainloop()

error is occuring here in config

buLogin.config(command=BuClick)

same questions which are already does not addressed my problem directly i checked the similar questions but couldn't able to find the answer that's why i post this question.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • 1
    The `grid` method returns `None`, not `self`. So all those variables you created don't hold your labels and entries and so on, they hold `None`. So, when you call `buLogin.config`, you're trying to call the `config` method of `None`, not of a `Button`. Hence the error. You did this right with `frame`; you just have to do the same for your other widgets. – abarnert Jul 12 '18 at 06:23
  • Ok tell me is it the right away to write the code, because it was compiling fine when i tried first time then problem occur afterwards – Jordan Negative Jul 12 '18 at 06:33
  • Remove the duplicate marked please because the similar question does not solve my problem thats why I post the question. – Jordan Negative Jul 12 '18 at 06:36
  • There are 4 duplicates marked. The second one's error is not just similar, but identical to yours, and the answer not only shows how to fix the code, but also explains the problem. There's further explanation, and examples, in the other three, that are all relevant as well. – abarnert Jul 12 '18 at 06:39
  • Oh I see that now i didn't open that question because it wasn't green when i was searching for the question and the heading wasn't the same as mine – Jordan Negative Jul 12 '18 at 07:31

1 Answers1

1

The issue seems to in this can be traced backed to this line

buLogin = ttk.Button(frame,text="Login").grid(row=2,column=1)

i think the .grid() is not returning anything. can you try like this

buLogin = ttk.Button(frame,text="Login")
buLogin.grid(row=2,column=1)

And ideally you should change all the usage of grid() like this.

This should work, I havn't tested this yet. please let us know the result.
Happy coding :)

Shiva Kishore
  • 1,611
  • 12
  • 29
  • 1
    Not only this line, but the same error is actually in almost all the lines and needs to be fixed in several places – FlyingTeller Jul 12 '18 at 06:27