map() function does not seem to be doing what it is supposed to do

Viewed 52

I'm trying to display a bunch of tkinter labels on the screen by storing the text and the other things like the value of padx and pady for that widget in a tuple nested within a list. I'm trying to iterate through each element of the list and display the label using the map() function. Here is a minimum example of my code

import tkinter as tk
import tkinter.ttk as ttk
from ttkthemes import ThemedTk


def func() :
    print("in func")
    def populate(tple) :
        print(f"In populate with tuple {tple}")
        label = ttk.Label(frame,text=tple[0],style=tple[1])
        label.grid(row=lst.index(tple),column=0,padx=tple[2],pady=tple[3],sticky=tple[4])
        frame.update_idletasks()

    tk.Grid.columnconfigure(frame, 0, weight=1)
    lst = [("This is text1","style1.TLabel",40,15,None),
        ("This is text2","style2.TLabel",20,15,tk.S)]
    map(populate, lst)

frame = ThemedTk(theme="black")
frame.config(bg="#424242")
style = ttk.Styles()
func()

frame.mainloop()

But for some reason, map() does not seem to be working. My question is, why is that? Is it because I'm not using map() like I'm supposed to? If so, how do I correctly use it?

1 Answers

map() will just return an iterator which need to be consumed in order to apply the function passed. Use something like list() or all() to consume it:

all(map(populate, lst))
Related