Python Forum
What units does the width parameter of a tkinter Listbox use? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: What units does the width parameter of a tkinter Listbox use? (/thread-28060.html)



What units does the width parameter of a tkinter Listbox use? - Pedroski55 - Jul-03-2020

I am tinkering with tkinter, trying to get the feel of it.

I make a nice window:

def myApp():
    root = Tk()
    root.title("Scrollbar Test")
    root.config(bg='light blue')
    root.geometry("640x480")
    xscrollbar = Scrollbar(root, orient=HORIZONTAL, width=20, activebackground='red', )
    yscrollbar = Scrollbar(root, orient=VERTICAL, width=20, activebackground='green', )
    xscrollbar.pack( side = BOTTOM, fill = X )
    yscrollbar.pack( side = RIGHT, fill = Y )

    # setting Listbox width = 75 makes it almost equal to the root window width of 640

    mylist = Listbox(root, xscrollcommand = xscrollbar.set, yscrollcommand = yscrollbar.set, width = 75)
    #mylist = Listbox(root, yscrollcommand = yscrollbar.set )
    for line in range(100):
       mylist.insert(END, "This is a very very long line with a line number added line number " + str(line))

    mylist.pack( side = LEFT, fill = BOTH )
    xscrollbar.config( command = mylist.xview )
    yscrollbar.config( command = mylist.yview )

    mainloop()
root.geometry is set to ("640x480")

then I set width = 75 for my Listbox.

But width = 75 is almost equal to 640 pixels!

What units does tkinter use for width parameters??


RE: What units does the width parameter of a tkinter Listbox use? - Larz60+ - Jul-03-2020

It is pixels.
See page 52 of Shipman Tkinter Referemce Manual (you can get a copy here: https://users.tricity.wsu.edu/~bobl/cpts481/tkinter_nmt.pdf )


RE: What units does the width parameter of a tkinter Listbox use? - deanhystad - Jul-04-2020

Listbox width is in characters, just like Entry and other controls that are used to display or enter text.