简体   繁体   English

在Python中使用Tkinter进行间距

[英]Spacing using Tkinter in Python

I'm experimenting with Tkinter for the first time. 我是第一次尝试Tkinter。 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. 我尝试使用\\ n,但这只将标签放在下面,而不是文本框下面。

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. 我建议您在此处使用Grid Geometry Manager而不是pack,因为您可以更好地控制小部件的放置。

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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