【问题标题】:Grid and Entry, Correct Alignment网格和条目,正确对齐
【发布时间】:2016-12-24 06:17:36
【问题描述】:

我将如何在 TkInter 中使用 Python 实现这一点?

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

【问题讨论】:

  • 有什么问题?显示您的代码。
  • 在点击“确认”按钮之前有什么方法可以破解代码?我遇到了一些疯狂的错误。
  • 什么错误?创建新问题并输入所有信息 - 带有完整的错误消息(回溯)。

标签: python user-interface tkinter


【解决方案1】:

或多或少:

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

【讨论】:

    猜你喜欢
    • 2011-10-10
    • 2019-07-20
    • 2018-04-08
    • 1970-01-01
    • 2022-06-20
    • 1970-01-01
    • 2014-02-08
    相关资源
    最近更新 更多