I am a beginner in tkinter and has been playing around with what I have learnt so far. The following is the code which I find is only relevant to answer my question and below that I have attached the picture of the gui I have got so far.
# Frame for the time spinners
timeFrame = tkinter.LabelFrame(mainWindow, text="Time")
timeFrame.grid(row=3, column=0, sticky="new")
# Time spinners
hourSpinner = tkinter.Spinbox(timeFrame, width=2, values=tuple(range(0, 24)))
minuteSpinner = tkinter.Spinbox(timeFrame, width=2, from_=0, to=59)
secondSpinner = tkinter.Spinbox(timeFrame, width=2, from_=0, to=59)
hourSpinner.grid(row=0, column=0)
tkinter.Label(timeFrame, text=":").grid(row=0, column=1)
minuteSpinner.grid(row=0, column=2)
tkinter.Label(timeFrame, text=":").grid(row=0, column=3)
secondSpinner.grid(row=0, column=4)
timeFrame.config(padx=36)
canvas = tkinter.Canvas(mainWindow, width=50, height=50, bg="red")
canvas.grid(row=4, column=0)
Here I can not seem to understand from where the padding between the label frame containing the time component and the red canvas is coming from. (I have highlighted the padding I am referring to in yellow using the snipping tool.)
I feel like there should be no padding between the label frame and the red canvas and the canvas should start from somewhere around the label frame ends.
I would be grateful if anyone could point me out from where this padding is coming from and how to make the canvas start from where the label frame ends?
However, if anyone reading this question finds that he/she needs to look at the complete code in order to answer, I have attached the complete code I have typed to build this below,
try:
import tkinter
except ImportError: # Python2
import Tkinter as tkinter
import os
mainWindow = tkinter.Tk()
mainWindow.title("Grid Demo")
mainWindow.geometry("640x480+320+125")
label = tkinter.Label(mainWindow, text="Tkinter Grid Demo")
label.grid(row=0, column=0, columnspan=3)
mainWindow.columnconfigure(0, weight=1)
mainWindow.columnconfigure(1, weight=1)
mainWindow.columnconfigure(2, weight=3)
mainWindow.columnconfigure(3, weight=3)
mainWindow.columnconfigure(4, weight=3)
mainWindow.rowconfigure(0, weight=1)
mainWindow.rowconfigure(1, weight=10)
mainWindow.rowconfigure(2, weight=1)
mainWindow.rowconfigure(3, weight=3)
mainWindow.rowconfigure(4, weight=3)
fileList = tkinter.Listbox(mainWindow)
fileList.grid(row=1, column=0, rowspan=2, sticky="nsew")
fileList.config(relief="sunken", borderwidth=2)
for zone in os.listdir(r"C:\Windows\System32"):
fileList.insert(tkinter.END, zone)
listScroll = tkinter.Scrollbar(mainWindow, orient="vertical", command=fileList.yview)
fileList.config(yscrollcommand=listScroll.set)
listScroll.grid(row=1, column=1, rowspan=2, sticky="nsw")
# Frame for the radio buttons
optionFrame = tkinter.LabelFrame(mainWindow, text="File Details")
optionFrame.grid(row=1, column=2, sticky="ne")
rbValue = tkinter.IntVar()
rbValue.set(3)
# Radio Buttons
radio1 = tkinter.Radiobutton(optionFrame, text="Filename", value=1, variable=rbValue)
radio2 = tkinter.Radiobutton(optionFrame, text="Path", value=2, variable=rbValue)
radio3 = tkinter.Radiobutton(optionFrame, text="Timestamp", value=3, variable=rbValue)
radio1.grid(row=0, column=0, sticky="w")
radio2.grid(row=1, column=0, sticky="w")
radio3.grid(row=2, column=0, sticky="w")
# Widget to display the result
resultLabel = tkinter.Label(mainWindow, text="Result")
resultLabel.grid(row=2, column=2, sticky="nw")
result = tkinter.Entry(mainWindow)
result.grid(row=2, column=2, sticky="sw")
# Frame for the time spinners
timeFrame = tkinter.LabelFrame(mainWindow, text="Time")
timeFrame.grid(row=3, column=0, sticky="new")
# Time spinners
hourSpinner = tkinter.Spinbox(timeFrame, width=2, values=tuple(range(0, 24)))
minuteSpinner = tkinter.Spinbox(timeFrame, width=2, from_=0, to=59)
secondSpinner = tkinter.Spinbox(timeFrame, width=2, from_=0, to=59)
hourSpinner.grid(row=0, column=0)
tkinter.Label(timeFrame, text=":").grid(row=0, column=1)
minuteSpinner.grid(row=0, column=2)
tkinter.Label(timeFrame, text=":").grid(row=0, column=3)
secondSpinner.grid(row=0, column=4)
timeFrame.config(padx=36)
canvas = tkinter.Canvas(mainWindow, width=50, height=50, bg="red")
canvas.grid(row=4, column=0)
mainWindow.mainloop()
