Python Forum

Full Version: What units does the width parameter of a tkinter Listbox use?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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??
It is pixels.
See page 52 of Shipman Tkinter Referemce Manual (you can get a copy here: https://users.tricity.wsu.edu/~bobl/cpts...er_nmt.pdf )
Listbox width is in characters, just like Entry and other controls that are used to display or enter text.