[英]TKinter Python GUI alignment
I have the following code for my GUI: 我的GUI有以下代码:
root = Tk()
draft = Frame(root)
draft.grid()
root.title("test")
var = StringVar()
emailLabel = Label(draft, text="E-Mail:")
emailLabel.grid(row = 0, column = 0)
email = Entry(draft, justify=LEFT)
email.grid(row = 0, column = 1)
email.insert(0, "E-Mail")
passLabel = Label(draft, text="Pass:")
passLabel.grid(row = 1, column = 0)
password = Entry(draft, justify=LEFT, show="*")
password.grid(row = 1, column = 1)
password.insert(0, "Password")
start = Button(draft, text = "Start")
start.grid(row = 2, column = 0)
stop = Button(draft, text = "Stop")
stop.grid(row = 2, column = 1)
status = Text(draft)
status.grid(row = 3)
status.insert(INSERT, "TESTING")
However, it's not lining up the way I want it. 但是,它并没有按照我想要的方式排列。 I want the label and textboxes aligned to the left not the right, and the status text box to take up the entire size of the bottom (It's more or less a log). 我希望标签和文本框与左侧而不是右侧对齐,并且状态文本框占用底部的整个大小(或多或少是一个对数)。
Here's a screenshot: 这是屏幕截图:
To make the Text
widget span over multiple columns, use the columnspan
argument: 要使“ Text
小部件跨越多列,请使用columnspan
参数:
status.grid(row=3, columnspan=2)
Additionally, you can use the sticky
parameter in the grid
method to make the widgets occupy as many space as possible. 此外,您可以在grid
方法中使用sticky
参数来使小部件占据尽可能多的空间。 Use this in every grid
call: 在每个grid
调用中使用此命令:
widget.grid(..., sticky=N+W+E+S)
If you want the labels to be smaller, you have to rethink your layout a bit. 如果要缩小标签,则必须重新考虑一下布局。
(Little note: it's not suggested to import *
from tkinter. import tkinter as tk
is preferred.) (注意:不建议从tkinter导入*
。首选tkinter import tkinter as tk
。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.