How to fit Tkinter listbox to contents

后端 未结 3 964
执笔经年
执笔经年 2020-12-18 07:15

I\'m adding strings to a listbox using the code below. When I run the code and the window opens, the longer strings get clipped as the window is not large enough (see screen

3条回答
  •  情歌与酒
    2020-12-18 07:20

    Resetting the listbox width worked for me. I used the Oblivion's answer and noticed that the width is always zero.

    listbox = tk.Listbox(master, selectmode=tk.SINGLE)
    listbox.config(width=0)
    

    I also recommend to reset the root window geometry after reloading a content of the list. Otherwise if user manually extends a window the window would stop accommodate size of its content.

    root.winfo_toplevel().wm_geometry("")
    

提交回复
热议问题