代码:http://pastebin.com/nXqFT7wz
import tkinter as tk
import tkinter.messagebox
def mbox(title, text):
tk.messagebox.showinfo(title, text)
def calculate():
num1 = num_1.get()
num2 = num_2.get()
total = int(num1) + int(num2)
mbox("Your total is: ", total)
root = tk.Tk()
label_1 = tk.Label(root, text="First Number")
label_2 = tk.Label(root, text="Second Number")
num_1 = tk.Entry(root)
num_2 = tk.Entry(root)
button_1 = tk.Button(root, text="Login", command=calculate)
label_1.grid(row=0)
label_2.grid(row=1)
num_1.grid(row=0, column=1)
num_2.grid(row=1, column=1)
button_1.grid(row=2, columnspan=2)
root.geometry("218x70")
root.resizable(0, 0)
root.title("Adder")
root.mainloop()
为什么,当我运行它时,按钮不是窗口中使用的两列宽度?从理论上讲,按钮应该是标签的宽度和条目(两列),但它只是在对话框中居中显示。