我正在尝试编写一个 GUI,它将在窗口的左上角显示三个按钮,在窗口的右上角显示四个按钮。我试图通过创建不同的框架来做到这一点:一个“左”框架,我在其中放置第一个按钮组,稍后我将在其中添加更多按钮。一个“左上角”框架,我在其中添加了第一组剩余的两个按钮。我适合第二组的前三个按钮的“右上角”框架。最后是一个“正确”的框架,我适合最后一个按钮,稍后我将在其中添加更多按钮,如附图所示。
但问题是左上和右上的框架冲突并相互堆叠,另外右上的框架堆叠在右框架的顶部,有没有人解决这个问题?
这是当前的 GUI:
这就是我想要实现的目标:
from tkinter import *
import tkinter as tk
from tkinter import messagebox
win = tk.Tk()
width_value = win.winfo_screenwidth()
height_value = win.winfo_screenheight()
win.geometry(f"{width_value}x{height_value}+0+0")
win.resizable(False, True)
win.title("Test GUI")
leftFrame = tk.Frame(win)
leftFrame.pack(side=LEFT, anchor=N)
homeImg = PhotoImage(file="home_icon.png")
homeb = Button(leftFrame, image=homeImg, command=homeMenu, height=100,
width=100).pack(padx=10, pady=10)
topLeftFrame = tk.Frame(win, width=200, height=100)
topLeftFrame.pack(side=TOP, anchor=W)
rgbmenuImg = PhotoImage(file="rgb_icon.png")
rgbmenub = Button(topLeftFrame, image=rgbmenuImg, command=rgbmenu, height=100, width=100)
thermalmenuImg = PhotoImage(file="thermal_icon.png")
cameraImg = PhotoImage(file="camera_icon.png")
thermalmenub = Button(topLeftFrame, image=thermalmenuImg, command=thermalmenu, height=100, width=100)
rgbmenub.grid(row=0, column=2, padx=10, pady=10)
thermalmenub.grid(row=0, column=3, padx=10, pady=10)
topRightFrame = tk.Frame(win, width=300, height=100)
topRightFrame.pack(side=TOP, anchor=E)
settImg = PhotoImage(file="settings_icon.png")
settingb = Button(topRightFrame, image=settImg, command=settings, height=100, width=100)
infoImg = PhotoImage(file="copyright_icon.png")
infob = Button(topRightFrame, image=infoImg, command=copyright, height=100, width=100)
loginImg = PhotoImage(file="login_icon.png")
loginb = Button(topRightFrame, image=loginImg, command=login, height=100, width=100)
settingb.grid(row=0, column=1, padx=10, pady=10)
infob.grid(row=0, column=2, padx=10, pady=10)
loginb.grid(row=0, column=3,padx=10, pady=10)
rightFrame = tk.Frame(win)
rightFrame.pack(side=RIGHT, anchor=N)
exitImg = PhotoImage(file="exit_icon.png")
exitb = Button(rightFrame, image=exitImg, command=quit, height=100, width=100).pack(padx=10, pady=10)
dema = Button(rightFrame, text="DEMA Intranet", command=dema_intranet).pack(padx=10, pady=10)
win.mainloop()