What is the "text" value in the following code?

I am playing with the tkinter library and actually having the code, where I don’t understand what is a text value in text=text. It is seemingly connected with the text attribute of the show_popup function because if I rename it, it doesn’t work properly. I would expect to find it in tkinter help, but I wasn’t able to find it there.

import tkinter as tk 
popup = tkinter.Tk()

def show_popup(text):
    popup = tk.Tk() 
    popup.geometry("300x150")

    popup.title("Krávy útočí!") 

    label = tk.Label(popup, text=text) 
    label.pack() 

    close_button = tk.Button(popup, text="Spláchnout", command=popup.destroy)
    close_button.pack()

    popup.mainloop()

a, b, c, d, e, f, g, h, i, j, k = "(", "_", ")", "o", "/", "-", "\\", "|", "*", " ", "\n"
text_to_display = "".join([j * 11, a, b * 2, c, k, j * 11, a, d * 2, c, k, j*4, e, f*7, g, e, k, j*3, e, h, j*7, h*2, k, j*2, i, j, h, j*7, h*2, k])
show_popup(text_to_display)

text=text means you are sending the contents of the variable “text” (the right-hand instance) as the keyword argument “text” (the left-hand instance) when calling the tk.Label method. You could rename the argument in both places to something else and it would continue to work.

def show_popup(message):

    label = tk.Label(popup, text=message)
2 Likes

So basically it looks like an anchor, to the widget which will receive “show_popup” contents.