当前位置: 动力学知识库 > 问答 > 编程问答 >

user interface - TKinter Python GUI alignment

问题描述:

I have the following code for my 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:

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. Use this in every grid call:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: