Skip to content Skip to sidebar Skip to footer

Python Tkinter Text Widget Fill Fixed Sized Frame Using Grid

Running Python 3.4.2 and Tkinter 8.6 on a Raspberry Pi. I want to create a Text widget that fills a fixed sized frame using the grid layout manager. If you run the code below, y

Solution 1:

You need to configure the grid to give the row and column a nonzero weight so that they expand

from tkinter import *

class Test(Tk):
  def __init__(self):
    Tk.__init__(self)
    self.grid_columnconfigure(0, weight=1)
    self.grid_rowconfigure(0, weight=1)
    self.text = frameText(self)
    self.geometry('{}x{}'.format(800, 600))   

def frameText(frame, **kw):
  ysb = Scrollbar(frame)
  xsb = Scrollbar(frame, orient = HORIZONTAL)
  text = Text(frame, **kw)
  ysb.configure(command = text.yview)
  xsb.configure(command = text.xview)
  text.configure(yscrollcommand = ysb.set, xscrollcommand = xsb.set)
  text.grid(row = 0, column = 0, sticky = N+E+S+W)
  ysb.grid(row = 0, column = 1, sticky = "ns")
  xsb.grid(row = 1, column = 0, sticky = E+W)
  return text

if __name__ == '__main__':
  Test().mainloop()

Post a Comment for "Python Tkinter Text Widget Fill Fixed Sized Frame Using Grid"