How to group two sets of buttons on each top corner of the screen using Tkinter? How to group two sets of buttons on each top corner of the screen using Tkinter? tkinter tkinter

How to group two sets of buttons on each top corner of the screen using Tkinter?


It will be much better if you use grid() geometry manager as you have much finer control over your positioning of widgets. With pack() you can mess up things pretty easily. Note that I have drawn the borders for you to realise that I have changed things a bit. You can see the Frames clearly in the picture.

import tkinter as tkfrom tkinter import messageboxwin = 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")win.grid_columnconfigure(0, weight=1)win.grid_columnconfigure(1, weight=1)topLeftFrame = tk.Frame(win, relief='solid', bd=2)topLeftFrame.grid(row=0, column=0, padx=10, sticky="w")homeImg = tk.PhotoImage(file="ex1.png")homeb = tk.Button(topLeftFrame, image=homeImg, height=100, width=100).grid(row=0, column=0, padx=10, pady=10)rgbmenuImg = tk.PhotoImage(file="ex1.png")rgbmenub = tk.Button(topLeftFrame, image=rgbmenuImg, height=100, width=100)thermalmenuImg = tk.PhotoImage(file="ex1.png")cameraImg = tk.PhotoImage(file="ex1.png")thermalmenub = tk.Button(topLeftFrame, image=thermalmenuImg, height=100, width=100)rgbmenub.grid(row=0, column=1, padx=10, pady=10)thermalmenub.grid(row=0, column=2, padx=10, pady=10)topRightFrame = tk.Frame(win, relief='solid', bd=2)topRightFrame.grid(row=0, column=1, padx=10, sticky="e")settImg = tk.PhotoImage(file="ex1.png")settingb = tk.Button(topRightFrame, image=settImg, height=100, width=100)infoImg = tk.PhotoImage(file="ex1.png")infob = tk.Button(topRightFrame, image=infoImg, height=100, width=100)loginImg = tk.PhotoImage(file="ex1.png")loginb = tk.Button(topRightFrame, image=loginImg, height=100, width=100)settingb.grid(row=0, column=0, padx=10, pady=10)infob.grid(row=0, column=1, padx=10, pady=10)loginb.grid(row=0, column=2,padx=10, pady=10)exitImg = tk.PhotoImage(file="ex1.png")exitb = tk.Button(topRightFrame, image=exitImg, command=quit, height=100, width=100).grid(row=0, column=3, padx=10, pady=10)leftFrame = tk.Frame(win, relief='solid', bd=2)leftFrame.grid(row=1, column=0, padx=10, pady=10, sticky="nw")tk.Button(leftFrame, text="Example 1").grid(row=1, column=0, pady=5)tk.Button(leftFrame, text="Example 2").grid(row=2, column=0, pady=5)tk.Button(leftFrame, text="Example 3").grid(row=3, column=0, pady=5)rightFrame = tk.Frame(win, relief='solid', bd=2)rightFrame.grid(row=1, column=1, padx=10, pady=10, sticky="ne")dema = tk.Button(rightFrame, text="DEMA Intranet")dema.grid(row=0, column=0, pady=5)tk.Button(rightFrame, text="Example 4").grid(row=1, column=0, pady=5)tk.Button(rightFrame, text="Example 5").grid(row=2, column=0, pady=5)tk.Button(rightFrame, text="Example 6").grid(row=3, column=0, pady=5)win.mainloop()

enter image description here

P.S. I had just one 50x50 "home" icon.