简体   繁体   中英

Spacing using Tkinter in Python

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: 结果窗口

How would you suggest I fix this?

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM