2
import tkinter as tk
root = tk.Tk()
root.state('zoomed')
text1 = tk.Text(state=tk.DISABLED)

scroll = tk.Scrollbar(root, command=text1.yview)
text1.configure(yscrollcommand=scroll.set)
text1.grid(row=1, column=1, sticky='we')
scroll.grid(row=1, column=2, sticky="nse")

root.mainloop()

How do I make the Text box fill the X axis? (sticky='we' did not work for me)

yoav
  • 324
  • 4
  • 22

2 Answers2

2
import tkinter as tk
root = tk.Tk()
root.state('zoomed')

text1 = tk.Text(state=tk.DISABLED)
scroll = tk.Scrollbar(root, command=text1.yview)
text1.configure(yscrollcommand=scroll.set)

text1.grid(row=1, column=0,sticky='we')
scroll.grid(row=1, column=1, sticky="ns")

root.grid_columnconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=0)

root.mainloop()

I've added the parameter weight to the columns in that grid, which basically is a relationship between the columns. Please see, What does 'weight' do in tkinter? to get a more detailed answer.

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
0

According to title:

What is the use of sticky in Python tkinter ?

When the widget is smaller than the cell, sticky is used to indicate which sides and corners of the cell the widget sticks to. The direction is defined by compass directions: N, E, S, W, NE, NW, SE, and SW and zero.

Extracted from this website

so sticky defines on which point the cell has to stick.

But according to your requirement you need to use weight option. weight option describes how much free space should a widget use.

see this question for more details.

Faraaz Kurawle
  • 1,085
  • 6
  • 24