0

I'm experimenting with Tkinter for the first time. I'm writing an interface for a caesar cipher program. How can I put the second label and text box underneath the first? I tried using \n but that only put the label underneath, not the textbox.

from tkinter import *

top=Tk()

text= Text(top)
text.insert(INSERT, "This is a Caesar Cipher encrypter.")
L1 = Label(top, text="Enter your text here")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)

L2 = Label(top, text="Enter your key here")
L2.pack( side = LEFT)
E2 = Entry(top, bd =5)
E2.pack(side = RIGHT)

top.mainloop()

Gives me: The resulting window

How would you suggest I fix this?

1 Answer 1

2

I would recommend you to use the Grid Geometry manager instead of pack here as you have much finer control over the placement of your widgets.

from tkinter import *

top=Tk()

text= Text(top)
text.insert(INSERT, "This is a Caesar Cipher encrypter.")
L1 = Label(top, text="Enter your text here")
L1.grid(row=0, column=0)
E1 = Entry(top, bd =5)
E1.grid(row=0, column=1)

L2 = Label(top, text="Enter your key here")
L2.grid(row=1, column=0)
E2 = Entry(top, bd =5)
E2.grid(row=1, column=1)

top.mainloop()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.