0

I am trying to make it so that the "Add Next Set" button displays the entered data in the textbox. Like for example:

display_example

The next step would be to apply the data from each previous entry and insert the data into the textbox with this ideal format. As show in the example.

display_example2

Any tips on how to format the data in the textbox?

Here is some code for context:

def insert_into_textbox(): #generates input fields for the next set of items

    #get the inputs
    handling_unit = e3.get()
    pieces = e4.get()
    description = e5.get()
    length = e6.get()
    width = e7.get()
    height = e8.get()
    weight = e9.get()
    classification = e10.get()

    textbox_display = (handling_unit+"   "+pieces+"   "+description+"   "+length+"   "+width+"   "+height+"   "+weight+"   "+classification)
    textbox.insert("end",textbox_display)
    e3.delete(0, "end")
    e4.delete(0, "end")
    e5.delete(0, "end")
    e6.delete(0, "end")
    e7.delete(0, "end")
    e8.delete(0, "end")
    e9.delete(0, "end")
    e10.delete(0, "end")

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)

textbox=Text(master, width=9, borderwidth=5, height=7)
textbox.grid(row=5, column=1, columnspan=9, sticky="nsew")


b0 = Button(master, text = "Add Next Set", bg="white", fg="black", font=arial8, command=insert_into_textbox)

mainloop()

Here is the output

ui4

How to properly format the display to match the ideal example in picture 2?

minTwin
  • 1,181
  • 2
  • 21
  • 35
  • 1
    I think you are looking for the answers from [this](https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces) post. – Henry Yik Mar 16 '20 at 06:54
  • 1
    Please make the code in your question a runnable example. – martineau Mar 16 '20 at 07:50
  • 1
    It is hard to align the text in `Text` widget with the `Entry` widgets because the width of the `Entry` borders may not match the width of a character of the font used in `Text` widget. – acw1668 Mar 16 '20 at 10:19

1 Answers1

0

The link that Henry Yik provided was very helpful. I made the following changes to the code.

textbox_display = (handling_unit.ljust(10)+pieces.ljust(11)+description.ljust(11)+length.ljust(10)+width.ljust(11)+height.ljust(11)+weight.ljust(10)+classification+"\n")

Or alternatively

textbox_display = "{:>12} {:>13} {:>14} {:>13} {:>13} {:>13} {:>13} {:>13}".format(handling_unit, pieces, description, length, width, height, weight, classification)

Yields the following result: enter image description here

minTwin
  • 1,181
  • 2
  • 21
  • 35