user1584421
user1584421

Reputation: 3863

Tkinter - Fill a frame with a text widget, using place()

I am trying to fill a frame with a text widget and a scrollbar.

I cannot get the text to fill the frame and i have tried many different approaches and things i saw online.

The problem is i am using place(), while most of the tutorials and asnwers ar about grid().

This is my code:

 # --- frame 5 - SERIAL PRINTOUT ---

    frame5 = tk.Frame(root, bg='#80c1ff', bd=5)
    frame5.place(relx = 0, rely = 0.4, relwidth = 1, relheight = 0.4)
    scrollbar = tk.Scrollbar(frame5)
    scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
    scrollbar.config(command=log.yview)
    log = tk.Text ( frame5, width=30, height=30, takefocus=0)
    log.pack()
    # attach text box to scrollbar
    log.config(yscrollcommand=scrollbar.set)

    # --- frame 5 - SERIAL PRINTOUT ---

Increasing width and height is not something i would like, because modifying the parent frame, will put me in a position to modify the text widget as well. Isn't there a method, or setting to make it fill the parent frame automatically?

Upvotes: 0

Views: 1617

Answers (1)

acw1668
acw1668

Reputation: 46841

If you want the Text widget to fill the available space inside its parent frame, you need to tell the pack layout manager via fill and expand options of pack():

log.pack(fill='both', expand=1)

Upvotes: 1

Related Questions