Entry field with submit button in python?

13,965

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()
Share:
13,965
EatMyApples
Author by

EatMyApples

I started Programming with Python about half a year ago. I know quite a lot about html and c++

Updated on June 04, 2022

Comments

  • EatMyApples
    EatMyApples almost 2 years

    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.