It's the first time I'm using Tkinter and I'm trying to realize a simple GUI, with a ScrolledText
on the top and a text field with a button on the bottom, so that it looks like what is shown in the first image below.
The thing that I don't understand is the following: When I tried to resize the window vertically, the text field and the button disappear, leaving just the scrollable text, as shown in the second image below.
But what I would expect is also the scrollable text to resize, leaving everything visible.
I've tried to use a fixed height for the scrollable text and I think all the weights of the columns/rows are OK, but I still can't find the issue. (The green and red backgrounds are there for being certain where the frames were.)
Here's the code I used:
import tkinter as tk
from tkinter import ttk
import tkinter.scrolledtext as scrolledtext
top = tk.Tk()
# GRID CONFIG
top.grid_rowconfigure((0,1), weight=1)
top.grid_columnconfigure(0, weight=1)
# FRAMES
UpFrame = tk.Frame(top, bg='red')
DownFrame = tk.Frame(top, bg='green')
UpFrame.grid(column=0, row=0, sticky='nsew')
DownFrame.grid(column=0, row=1, sticky='sew')
UpFrame.grid_columnconfigure(0, weight=1)
UpFrame.grid_rowconfigure(0, weight=1)
DownFrame.grid_columnconfigure((0,1), weight=1)
# SCROLLABLE FRAME
scrollable_frame = scrolledtext.ScrolledText(UpFrame,
wrap = tk.WORD,
font = ("Times New Roman", 15))
scrollable_frame.grid(column=0, row=0, sticky='nsew')
# TEXT
my_msg = tk.StringVar()
my_msg.set("")
# TEXT FIELD AND SEND BUTTON
entry_field = tk.Entry(DownFrame, textvariable=my_msg)
entry_field.grid(row=0, column=0, sticky='nsew')
send_button = tk.Button(DownFrame, text="Send")
send_button.grid(row=0, column=1, sticky='nsew')
tk.mainloop()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…