网格和输入,正确的对齐

时间:2016-12-24 06:17:36

标签: python user-interface tkinter

enter image description here

我如何在TkInter中使用Python实现它?

输入两个数字作为宽度和高度,然后分别保存到Mapwidth和Mapheight。点击确认按钮后,窗口关闭。

1 个答案:

答案 0 :(得分:0)

或多或少:

import tkinter as tk

# --- function ---

def on_confirm():
    print('Mapwidth:', e1.get())
    print('Mapheight:', e2.get())
    root.destroy()

# --- main ---

root = tk.Tk()

l = tk.Label(root, text="Width")
l.grid(row=0, column=0)

e1 = tk.Entry(root)
e1.grid(row=0, column=1)

l = tk.Label(root, text="Height")
l.grid(row=1, column=0)

e2 = tk.Entry(root)
e2.grid(row=1, column=1)

b = tk.Button(root, text="Confirm", command=on_confirm)
b.grid(row=2, column=0, columnspan=2)

root.mainloop()