This is my sample code:
from tkinter import *
from tkinter import ttk, scrolledtext
class MainWindow:
def __init__(self):
self.parent=Tk()
self.parent.geometry("500x300+370+100")
self.parent.title("My Software")
self.Frame1=Frame(self.parent, background="#ffffff")
self.Frame1.place(x=10, y=10, width=400, height=250)
self.style=ttk.Style()
self.style.configure("InWhiteFrame.TButton", background="#ffffff", padding=0) # it makes "invisible" the extra 1px border in the ttk buttons.
self.Frame1.grid_columnconfigure(0, minsize=16)
self.Frame1.grid_columnconfigure(4, weight=1) # it adapts the Entry1 widgets to the available size.
self.Frame1.grid_columnconfigure(1, minsize=1) # 1px column to "delete" the extra 1px border from the ttk buttons (see the "test" button)
self.Frame1.grid_columnconfigure(3, minsize=10)
self.Frame1.grid_columnconfigure(5, minsize=8)
self.Frame1.grid_columnconfigure(7, minsize=1, pad=1)
self.Frame1.grid_columnconfigure(8, minsize=34, pad=34) # 1px column to "delete" the extra 1px border from the ttk buttons (see the "..." button)
self.Frame1.grid_rowconfigure(0, minsize=16, pad=16)
self.Frame1.grid_rowconfigure(2, minsize=12, pad=12)
self.Frame1.grid_rowconfigure(4, minsize=12, pad=12)
self.Frame1.grid_rowconfigure(6, minsize=30, pad=30)
ttk.Label(self.Frame1, text="bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla:", wraplength=514, background="#ffffff").grid(row=1, column=2, columnspan=7, sticky="w")
self.MyLabel=ttk.Label(self.Frame1, text="bla bla bla:", background="#ffffff")
self.MyLabel.grid(row=3, column=2, sticky="w")
self.Entry1=ttk.Entry(self.Frame1)
self.Entry1.grid(row=3, column=4, sticky="ew")
self.Button1=ttk.Button(self.Frame1, text="...", width=4, style="InWhiteFrame.TButton")
self.Button1.grid(row=3, column=6, columnspan=7, sticky="w")
self.TextBox=scrolledtext.ScrolledText(self.Frame1, wrap=WORD, height=6, font=("Segoe UI", 9))
self.TextBox.grid(row=5, column=2, columnspan=6, sticky="we")
self.Button2 = ttk.Button(self.Frame1, text="test", style="InWhiteFrame.TButton", command=self.ChangeMyLabel)
self.Button2.grid(row=7, column=1, columnspan=7, sticky="w")
self.parent.mainloop()
def ChangeMyLabel(self):
self.MyLabel.configure(text="bla bla bla bla bla bla:")
def main():
app=MainWindow()
if __name__=="__main__":
main()
in my frame (Frame1) I chosed to place the ttk widgets using the grid method. I configured eight columns. the first and the last two ones are really important for the design. the first one creates an extra space, and the second one helps to "hide" the extra border around the ttk button (Button2). see the below image to understand exactly what I mean:
Without the second column (composed by just one pixel) the ttk button (Button2) would be not align with the ScrolledText widget. it just a workaround to "delete" the annoying extra border placed around the ttk buttons. I tried to delete it with some options from the "Button2" but no ones solved the issue. I opened also a topic here, but unfortunately nobody know how to delete the extra border from the ttk buttons, probably because it's not possible.. I don't know.
Tkinter - How can I remove the background borders from ttk.Button?
This part of my code works perfectly but I can't say the same for the code that regards the last two columns. they are very similar to the two first ones. the eighth column should to crate an extra space (34px), and the seventh one (1px) should hide the extra border from the ttk button (Button1) but they doesn't work. see the image below:
As you can see, the widgets placed in the third row, composed by a label, an entry and a button, are not aligned to the ScrolledText widget.
My question is: how can I place the widgets in my frame (Frame1) in order to "hide" the extra border from the ttk buttons, and at the same time align all of them correctly as shown in the screenshot below?