I am currently having this problem in my program, where the text widget box for columns in the center should have the same width and height with the other column boxes.
def create_widgets(self):
tk.Label(self.master, text="Upload CSV File:").grid(row=1, column=2, padx=5, pady=5, sticky="w")
self.upload_button = tk.Button(self.master, text="Upload", command=self.upload_csv, font=("Arial", 11, "bold"), bg='blue', fg='white')
self.upload_button.grid(row=1, column=2, padx=3, pady=3)
# Add Text widgets for the columns from the CSV file
self.text_boxes = {}
csv_columns = ["Column1", "Column2", "Column3", "Column4", "Column5"]
for idx, col in enumerate(csv_columns):
text_box = tk.Text(self.master, height=20, width=40)
text_box.grid(row=2, column=idx, padx=5, pady=5)
self.text_boxes[col] = text_box
# Disable editing
self.text_boxes[col].config(state=tk.DISABLED)
self.predict_button = tk.Button(self.master, text="Predict", command=self.predict, font = ("Arial", 11, "bold"), bg= 'green', fg='white')
self.predict_button.grid(row=6, column=2, columnspan=1, padx=5, pady=5)
# Frame for output text
output_frame = tk.Frame(self.master)
output_frame.grid(row=8, column=2, columnspan=1, padx=5, pady=10)
# Label for the output title
output_title = tk.Label(output_frame, text="Output", font=("Arial", 15, "bold"), bg='blue', fg='white')
output_title.grid(row=0, column=0, columnspan=2, pady=(0, 5))
# Text widget for displaying output
self.output_text = tk.Text(output_frame, height=15, width=50, wrap=tk.WORD)
self.output_text.grid(row=1, column=0, columnspan = 2, padx=5, pady=(0, 5))
self.output_text.config(state=tk.DISABLED)
# Center the output frame within the window
output_frame.grid_columnconfigure(0, weight=1)
output_frame.grid_rowconfigure(1, weight=1)
output_frame.pack_propagate(False) # Prevent the frame from resizing to fit its contents
def create_text_boxes(self):
expected_colums = ["Land Area", "Usable Area", "Floors", "Price"]
for idx, col in enumerate(expected_colums):
text_box = tk.Text(self.master, height=20, width=35)
text_box.grid(row=2, column=idx, padx=5, pady=5)
self.text_boxes[col] = text_box
# Display CSV data in Text widgets
self.text_boxes[col].insert(tk.END, self.format_csv_data(col))
self.text_boxes[col].config(state = tk.DISABLED)
However, when I want to adjust the text widget for displaying the output of the calculations, the center text widget box on the columns will also adjust and it will have in between spaces. I tried everything, especially in adjusting the columns, pads, rows, and more and I still can’t figure out the problem. here’s the image
How to resolve it?
You should put output_frame
in column 0 with columnspan=len(csv_columns)
instead:
# Frame for output text
output_frame = tk.Frame(self.master)
output_frame.grid(row=8, column=0, columnspan=len(csv_columns), padx=5, pady=10)
Result:
0