In Button, why can the variable TEXT be passed to print_text() with a lambda function, but not in OptionMenu? When the program is run and a value is selected from the option menu, the following error is displayed:
TypeError: () takes 0 positional arguments but 1 was given
How could I pass TEXT to print_text() with a lambda function in OptionMenu?
Which confuses me even more, why does Pylint show the following errors for button = Button(...) and option_menu = OptionMenu(...) and how can it be resolved:
"Assigning result of a function call, where the function has no return".
from tkinter import Tk, Button, OptionMenu, StringVar
def print_text(some_text):
print(some_text)
main_window = Tk()
# Button
TEXT = "This works"
button = Button(main_window, text="Print to console",
command=lambda: print_text(TEXT)).pack() # works
# OptionMenu
selected_value_option_menu = StringVar(main_window)
OPTIONS = ["one", "two", "three"]
option_menu = OptionMenu(main_window, selected_value_option_menu, *OPTIONS,
command=lambda: print_text(TEXT)).pack() # does not work
main_window.mainloop()