DIEA
您可以创建两个单独的框架并将一个放在另一个的顶部我创建了 fc 和 fc2 并将 fc 放在 fc2 之上from random import *from math import *from tkinter import *def insert_1(): text.insert(END, "1")def insert_2(): text.insert(END, "2")def insert_3(): text.insert(END, "3")def insert_4(): text.insert(END, "4")def insert_5(): text.insert(END, "5")def insert_6(): text.insert(END, "6")def insert_7(): text.insert(END, "7")def insert_8(): text.insert(END, "8")def insert_9(): text.insert(END, "9")def insert_plus(): text.insert(END, "+")def insert_minus(): text.insert(END, "-")def insert_divide(): text.insert(END, ":")def insert_multiply(): text.insert(END, "*")def insert_ac(): text.delete(0.0, END)def insert_equals(): text.delete(0.0, END) text.insert(END, "Calculating...")calculator = Tk()fc = Frame(calculator)fc.grid(row=1)fc2 = Frame(calculator)fc2.grid(row = 2)text = Text(fc, width=20, height=1)bu1 = Button(fc2, text="1", activeforeground="white", activebackground="grey", command=insert_1)bu2 = Button(fc2, text="2", activeforeground="white", activebackground="grey", command=insert_2)bu3 = Button(fc2, text="3", activeforeground="white", activebackground="grey", command=insert_3)bu4 = Button(fc2, text="4", activeforeground="white", activebackground="grey", command=insert_4)bu5 = Button(fc2, text="5", activeforeground="white", activebackground="grey", command=insert_5)bu6 = Button(fc2, text="6", activeforeground="white", activebackground="grey", command=insert_6)bu7 = Button(fc2, text="7", activeforeground="white", activebackground="grey", command=insert_7)bu8 = Button(fc2, text="8", activeforeground="white", activebackground="grey", command=insert_8)bu9 = Button(fc2, text="9", activeforeground="white", activebackground="grey", command=insert_9)bu_ac = Button(fc2, text="AC", activeforeground="white", activebackground="grey", command=insert_ac)bu_plus = Button(fc2, text="+", activeforeground="white", activebackground="grey", command=insert_plus)bu_minus = Button(fc2, text="-", activeforeground="white", activebackground="grey", command=insert_minus)bu_divide = Button(fc2, text=":", activeforeground="white", activebackground="grey", command=insert_divide)bu_multiply = Button(fc2, text="x", activeforeground="white", activebackground="grey", command=insert_multiply)bu_equals = Button(fc2, text="=", activeforeground="white", activebackground="grey", command=insert_equals)text.grid(row = 1)bu1.grid(row=2, column=1)bu2.grid(row=2, column=2)bu3.grid(row=2, column=3)bu4.grid(row=3, column=1)bu5.grid(row=3, column=2)bu6.grid(row=3, column=3)bu7.grid(row=4, column=1)bu8.grid(row=4, column=2)bu9.grid(row=4, column=3)bu_plus.grid(row=2, column=4)bu_minus.grid(row=3, column=4)bu_divide.grid(row=4, column=4)bu_multiply.grid(row=2, column=5)bu_ac.grid(row=3, column=5)bu_equals.grid(row=4, column=5)