Entry field with submit button in python?

EatMyApples picture EatMyApples · Jun 12, 2012 · Viewed 11.6k times · Source

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.

Answer

Junuxx picture Junuxx · Jun 12, 2012

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()