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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
EatMyApples
  • 465
  • 6
  • 11
  • 18

1 Answers1

4

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()
Junuxx
  • 14,011
  • 5
  • 41
  • 71