@@ -17,7 +17,8 @@ def __init__(
1717 parent : ttk .Frame ,
1818 items = None ,
1919 selectmode = tk .MULTIPLE ,
20- height = None ,
20+ height = None ,
21+ width = None ,
2122 show_selection_controls = False ,
2223 ** kwargs ):
2324 """
@@ -26,6 +27,7 @@ def __init__(
2627 items (list, optional): List of items to populate the listbox.
2728 selectmode (str): Selection mode for the listbox (SINGLE, MULTIPLE, etc.).
2829 height (int, optional): Height of the listbox. Defaults to number of items.
30+ width (int, optional): Width of the listbox in characters. If None, listbox expands to fill available space.
2931 show_selection_controls (bool): Show Select All and Deselect All buttons.
3032 **kwargs: Additional Frame options.
3133 """
@@ -44,13 +46,16 @@ def __init__(
4446 self .content_frame .rowconfigure (1 , weight = 1 )
4547
4648 # Create listbox
47- self .listbox = tk .Listbox (
48- self .content_frame ,
49- selectmode = selectmode ,
50- height = height ,
51- yscrollcommand = self .scrollbar .set ,
52- exportselection = False ,
53- )
49+ listbox_options = {
50+ "selectmode" : selectmode ,
51+ "height" : height ,
52+ "yscrollcommand" : self .scrollbar .set ,
53+ "exportselection" : False ,
54+ }
55+ if width is not None :
56+ listbox_options ["width" ] = width
57+
58+ self .listbox = tk .Listbox (self .content_frame , ** listbox_options )
5459 self .listbox .grid (row = 0 , column = 0 , columnspan = 2 , sticky = "nsew" )
5560 self .scrollbar .config (command = self .listbox .yview )
5661
0 commit comments