user interface - Python's tkinter Buttons - How to get return values of functions from other buttons? -
I am working on a typewriter interface for an assignment that opens a file, reads and modifies it , Then it's a new file. I have such buttons that, when clicking, allow the user to browse their computer for the proper file. Those different functions return the filename ("Random InputFile.txt")
My problem is that I have a third button, which should take those two values and then use them in the process of reading / writing should do. I'm not sure how to give input / output filenames as a parameter to read / write tasks.
Should I pass the file name as a Global variable within the corresponding function? Tkinter.filedialog import from askopenfilename to tkinter.filedialog import askaveasfilename def openGUI (): wn = Tk () wn.title ("homework 10 - CSIS 153") openFileButton = button (wn, text = "open") Command = openFile) openFileButton.pack () openFileButton.place (bordermode = out, height = 90, width = 90) saveFileButton = button (wn, text = "save in ...", command = saveFile) SaveFileButton.pack () saveFileButton.place (bordermode = out, height = 90, width = 90, x = 110,) executeButton = button (wn, text = "run program", command = splitSentences (**** some, some type **** ) ExecuteButton.pack () executeButton.place (bordermode = out, height = 90, width = 123, x = 40, y = 115) wn.mainloop () def openFile (): inputFile = askopenfilename ()) Msg = " You are opening up: \ n \ n "+ str (Inpu Tuffy) messagebox. Returning filefile = askaveasfilename () Return output file df splitentence (infile, outfile): OpenFile with myFile as: #etc etc. / pre> You can not do anything However, the better way to do this is to create a square for your GUI, and provide any way to disable them as an example variable as the back on a button, so those lines There is no use of it in the end of the works and yes, the simplest thing is that
inputFile and
outputFile create global variables Area will be. Then, you will not need to pass them as the argument of
splitSentences () , that function will only reach them directly.
executeButton Unless you have the value for
inputFile and
outputFile variables, otherwise this function will throw an error
Comments
Post a Comment