簡體   English   中英

在Python中使用Tkinter進行間距

[英]Spacing using Tkinter in Python

我是第一次嘗試Tkinter。 我正在為凱撒密碼程序編寫接口。 如何將第二個標簽和文本框放在第一個標簽下方? 我嘗試使用\\ 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()

給我: 結果窗口

您如何建議我解決此問題?

我建議您在此處使用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