I'm missing some basic comprehension of how the tkinter dialogs are supposed to work with the rest of the code in a Python program. Perhaps my approach is not the best, but what I am trying to do is the following:
Run some code to select some files (works)
Parse the files (works)
Based on what is in the files, open a simple combo-box with options to choose from (doesn't work)
Based on the choice the user makes, perform different actions on the files (doesn't get this far)
tkinter has a very easy-to-use function to select a directory graphically:
root.dirname = askdirectory(initialdir = "/home/jon/Python/",title = "Choose directory")
I can use that any time during my program, select a directory, store it in root.dirname, and use root.dirname later in my program as necessary. I would like to do something very similar to that with a drop-down menu. I'm picturing something like the following:
selectedOption = dropdownbox(('Option1', 'Option2', 'Option3'))
Then a simple dialog box would open, presenting the user with a dropdown box with the three options. After the user chooses the option they want (and presses OK or something to that affect), the window closes and selectedOption contains the option that was selected. Then my code can continue and use selectedOption to determine what course to take.
The main gap in my understanding is how to open a tkinter dialog at an arbitrary location in my code and use the "result" of the dialog later in my code. All of the code I've been finding for tkinter comboboxes, etc, seem to be more along the lines of building a standalone application rather than a short dialog to make a decision and return control to the calling function. But I think I'm just missing something. Any help is appreciated.
EDIT: Added code based on Uriel's input
from tkinter import simpledialog
from tkinter import *
def returnResultFromSimpleDialog():
root = Tk()
root.result = simpledialog.askstring('Input', 'Enter a string') # title and description
root.withdraw()
return root.result
if __name__ == '__main__':
print(returnResultFromSimpleDialog())
This is very close to what I am wanting to do, except I want a window with a dropdown menu instead of a text box.