minTwin
minTwin

Reputation: 1395

How to change size of textbox so that it expands horizontally across the UI with tkinter and python

I am designing a UI and want to implement a textbox to display inputted data. For example, when Handling Unit is inputted in the to its corresponding entry field the data will be displayed and stored in the textbox. UIwithscrollbar

I want the change the width of the textbox so that is expands from column 1 to column 8. I've tried changing some parameters within the grid method, but it causes some formatting errors.

Here is some code for context:

e1 = Entry(master, borderwidth=5, width=12) #origin zip
e2 = Entry(master, borderwidth=5, width=12) #destination zip
e3 = Entry(master, borderwidth=5, width=12) #handling unit(s)
e4 = Entry(master, borderwidth=5, width=12) #piece(s)
e5 = Entry(master, borderwidth=5, width=13) #description(s)
e6 = Entry(master, borderwidth=5, width=12) #length(s)
e7 = Entry(master, borderwidth=5, width=12) #width(s)
e8 = Entry(master, borderwidth=5, width=12) #height(s)
e9 = Entry(master, borderwidth=5, width=12) #weight(s)
e10 = Entry(master, borderwidth=5, width=12) #class(s)

e1.grid(row = 0, column = 2, pady = 1, sticky="W")  #origin zip
e2.grid(row = 0, column = 4, pady = 1, sticky="W") #destination zip
e3.grid(row = 3, column = 1, pady = 1, sticky="W") #handling unit(s)
e4.grid(row = 3, column = 2, pady = 1, sticky="W") #piece(s)
e5.grid(row = 3, column = 3, pady = 1, sticky="W")  #description(s)
e6.grid(row = 3, column = 4, pady = 1, sticky="W")  #length(s)
e7.grid(row = 3, column = 5, pady = 1, sticky="W") #width(s)
e8.grid(row = 3, column = 6, pady = 1, sticky="W") #height(s)
e9.grid(row = 3, column = 7, pady = 1, sticky="W") #weight(s)
e10.grid(row = 3, column = 8, pady = 1, sticky="W") #class(s)

textbox=Text(master, width=9, borderwidth=5, height=7)
textbox.grid(row=5, column=0, columnspan=3)

scrollbar=Scrollbar(master, orient="vertical", command=textbox.yview)
scrollbar.grid(row=5, column=9, sticky=NS)
textbox.configure(yscrollcommand=scrollbar.set)

Upvotes: 0

Views: 56

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

I want the change the width of the textbox so that is expands from column 1 to column 8.

If that is the case, you need to tell it to span eight columns, not three. You also need to use the sticky attribute so that the text widget expands to fill the space it has been allocated.

textbox.grid(row=5, column=0, columnspan=8, sticky="nsew")

Upvotes: 2

Related Questions