嗨,伙計們,我正在構建一個簡單的計算器,但在放置按鈕的方法上遇到了問題.pack(),我想將“4”數字放在bottone5變數“7”數字下方的bottone1變數中。我知道該包使用所有剩余空間可用,但是如何使用 .pack() 將“4”放在“7”數字下方?謝謝,圖片和代碼供參考

from tkinter import *
window = Tk()
window.resizable(width=False, height=False)
foto_cestino = PhotoImage(file="cestino2.png")
foto_cancella = PhotoImage(file="daidaidao.png")
window.call('wm', 'iconphoto', window._w, PhotoImage(file="opopo.png"))
window.title("Calcolatrice")
window.geometry("670x355")
equation_text = ""
equation_lable = StringVar()
label = Label(window, textvariable=equation_lable, font=('Ink Free',20), bg="#01335A", fg="white", width=44, height=2)
label.pack()
bottone1 = Button(window, text="7", font=('Ink Free',20), width=5, height=1, bg="#008BC7",command=lambda: button_press("7"))
bottone1.configure(activebackground="#00A1E6")
bottone1.pack(side=LEFT,anchor=NW,padx=(2,0))
bottone2 = Button(window, text="8", font=('Ink Free',20), width=5, height=1, bg="#008BC7",command=lambda: button_press("8"))
bottone2.configure(activebackground="#00A1E6")
bottone2.pack(side=LEFT,anchor=NW)
bottone3 = Button(window, text="9", font=('Ink Free',20), width=5, height=1, bg="#008BC7",command=lambda: button_press("9"))
bottone3.configure(activebackground="#00A1E6")
bottone3.pack(side=LEFT,anchor=NW)
bottone4 = Button(window, text=" ", font=('Ink Free',20), width=3, height=1, bg="#FF9D12",command=lambda: operazioni(" "))
bottone4.configure(activebackground="#e87400")
bottone4.pack(side=LEFT,anchor=NW)
bottone20 = Button(window, text="x2", font=('Ink Free',20), width=3, height=1, bg="#FF9D12",command=lambda: button_press("^"))
bottone20.configure(activebackground="#e87400")
bottone20.pack(side=LEFT,anchor=NW)
bottone5 = Button(window, text="4", font=('Ink Free',20), width=5, height=1, bg="#008BC7",command=lambda: button_press("4"))
bottone5.configure(activebackground="#00A1E6")
bottone5.pack(side=LEFT,anchor=W)
window.mainloop()
uj5u.com熱心網友回復:
使用grid()函式,grid()基于行和列,所以在你的情況下更好,
完整指南:

uj5u.com熱心網友回復:
使用 place() 函式將 buttone5 放在按鈕 7 下,否則請按照本教程視頻
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/486932.html
