I am creating a To - Do List In Python, and I have to arrange 3 elements as I start. These include a Notebook in order to flip through notes and to - dos. The others are just labels with images on them. Here is the code. My question is that I'm not sure how I am supposed to go about putting these images on the grid. The Notebook, which is located Row 1, Column 0, is very large and causes the column 2 to shift all the way right, which gets rid of the ability to put two items in two columns close to each other in row 1. Here is the code.
from tkinter import *
import datetime
from tkinter import ttk
import tkinter as tk
from tkinter.scrolledtext import ScrolledText
root = Tk()
root.title("To - Do List")
root.geometry("1200x600")
root.configure(background = "white")
# Variable list:
content = ttk.Frame(root)
content.grid(column=0, row=0, sticky=(N, S, E, W))
Photo1= PhotoImage(file="Full Circle Image Icon Docs.png")
Photo2 = PhotoImage(file="To - Do List Label.png")
TasksList = ttk.Notebook()
Task1 = ttk.Frame(TasksList)
Task2 = ttk.Frame(TasksList)
TasksList.add(Task1, text = 'One')
TasksList.add(Task2, text = 'Two')
TasksList.grid(row=2, column=0, sticky=W)
root.columnconfigure(0, weight=0)
root.rowconfigure(0, weight=0)
Label(image=Photo1, bg="black", borderwidth=0, highlightthickness=0).grid(row=0, column=0, sticky=W)
Label(image=Photo2, borderwidth=0, highlightthickness=0).grid(row=0, column=1, sticky=W)
root.mainloop()
Help would be greatly appreciated. Thanks a lot guys!
Make the grid three columns wide and then set column weigth=1 to the third column to let it expand with the window. Then place the labels in column one and two.
Then let the TasksList fill all three columns with: columnspan=3
.
Also I put the TasksList in the second row and let it have weight=1 to expand with the window. See this example:
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry("500x600+800+50")
# Set which cols and rows should expand with window
root.columnconfigure(2, weight=1)
root.rowconfigure(1, weight=1)
TasksList = ttk.Notebook(root)
Task1 = ttk.Frame(TasksList)
Task2 = ttk.Frame(TasksList)
TasksList.add(Task1, text = 'One One One One One One')
TasksList.add(Task2, text = 'Two Two Two Two Two Two')
TasksList.grid(row=1, column=0, sticky=N+W, columnspan=3)
# Make the TaskList span all three columns ------^
Photo1= PhotoImage(file="test.gif")
Photo2 = PhotoImage(file="test.gif")
# Put labels in root
Label(root, image=Photo1, bd=0).grid(row=0, column=0, sticky=W)
Label(root, image=Photo2, bd=0).grid(row=0, column=1, sticky=W)
# Don't put anything in column=2
root.mainloop()
In row=0 the third column (empty) will expand to fill the window. In row=1 the TasksList will expand to fill the window. See The Tkinter Grid Geometry Manager for more information.