3

I would like to make a password and username entry field. And a "submit" button on the bottom. This is what i have got so far but i cant figure out how to work with the grid:

So this is the code that will create 1 entry field, names "username"

from Tkinter import *
top = Tk()
L1 = Label(top, text="User Name")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)
top.mainloop()

and this is my code for the submit button:

MyButton1 = Button(master, text="Submit", width=10, command=callback)
MyButton1.grid(row=0, column=0)

I just don't know how to put these two codes together.

1 Answer 1

5

First of all, don't mix pack and grid.

Second, your button has a different parent than your entry. Replace master with top. And don't forget to actually implement your callback function, or it won't work.

from Tkinter import *

def callback():
    print 'You clicked the button!'

top = Tk()
L1 = Label(top, text="User Name")
L1.grid(row=0, column=0)
E1 = Entry(top, bd = 5)
E1.grid(row=0, column=1)

MyButton1 = Button(top, text="Submit", width=10, command=callback)
MyButton1.grid(row=1, column=1)

top.mainloop()
Sign up to request clarification or add additional context in comments.

2 Comments

so you recommend using the grid instead of pack?
@VincenTTTTTTTTTTTT: Yes, grid allows you much more control than pack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.