Using Tkinter and Python. Already created a window for the buttons to be placed on. I want there to be four buttons to appear, and I want to be able to click one of the four buttons, and be able for it to set the selection variable = "whatever I clicked", so that I can then use this variable later to call an API. When I run the program and click on the "General knowledge" button and print the selection, it does correctly print "General knowledge", but then when I try to return this selection variable it just doesn't work and I don't know why.
def select1(): selection = "General Knowledge" print(selection) def select2(): selection = "Science" def select3(): selection = "Entertainment" def select4(): selection = "Miscellaneous" button1 = tk.Button(text = "General Knowledge", command = select1) button1.place(x=100, y=100) button2 = tk.Button(text = "Science", command = select2) button2.place(x=100, y=140) button3 = tk.Button(text = "Entertainment", command = select3) button3.place(x=100, y=180) button4 = tk.Button(text = "Miscellaneous", command = select4) button4.place(x=100, y=220)