Add internal padding to text widget on only one side

Question:

So in my program I have a text widget and I want to add padding between the actual text and the side of the widget, but only on one side. You can do it on both sides by declaring the padx when the widget is being created. This is my code so far:

inputEntry = Text(bd=0, bg="#d9d9d9", highlightthickness=0, font='calibri', pady=10)

I would like to also add padx to only one side of the text widget (The right side). I tried padx=(0, 20) but it didn’t work. Is there anything that can do this?

Thanks!

EDIT:

Here is all of my code:

inputEntryImg = PhotoImage(file=resource_path("inputEntry.png"))
inputEntryBg = mainWindowCanvas.create_image(400.0, 168.5, image=inputEntryImg)
inputEntry = Text(mainWindow, bd=0, bg="#d9d9d9", highlightthickness=0, font='calibri')
inputEntryScroll = Scrollbar(inputEntry)
inputEntry.configure(yscrollcommand=inputEntryScroll.set)
inputEntry.pack(side=LEFT)
inputEntryScroll.pack(side=RIGHT, fill=Y)
inputEntry.place(x=41.0, y=83, width=718.0, height=169)
Asked By: Joshilovessnow

||

Answers:

You can put the text widget inside a frame and add the required padding when using the layout function:

inputFrame = Frame(bg='#d9d9d9')
inputFrame.pack()
inputEntry = Text(inputFrame, bd=0, bg='#d9d9d9', highlightthickness=0, font='calibri')
inputEntry.pack(padx=(0,10), pady=10)

Note that it is recommended to specify the parent of widget when creating the widget.

Answered By: acw1668
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.