I have some problems with Tkinter, I want so retrieve the selected item of an option menu when pressing a button, but when testing the funcionality with a small testfuntion 'getdataset', I only get the predefined datavariable ('Birthdata') as an output so it seems that the datavariable.get() method is not returning the selected option in the optionmenu. I have looked everywhere but cannot seem to find the answer. Any help is appreciated.
Code with option menu
root = Tk()
root.configure(background='white')
def getdataset():
print(datavariable.get())
datavariable = StringVar(root)
datavariable.set('Birthdata')
PickData = OptionMenu(root, datavariable,'Birthdata', 'Marriagedata', 'Deathdata',command=getdataset)
PickData.grid(column=1,columnspan=2,row=1)
Code to initialize test function with button click:
wordcloud = Button(root, text = 'Word Cloud', bg='white', width=20, height = 5, command=getdataset)
Output after multiple button clicks:
Birthdata
Birthdata
Birthdata
I w