from tkinter import * from tkinter import filedialog def openFile(): filepath = filedialog.askopenfile() file = open(filepath), ‘r’) print(file.read()) file.close() window = Tk() button = Button(text="Open",command=openFile) button.pack() window.mainloop() C:\Users\Hp\PycharmProjects\pythonProject\venv\Scripts\python.exe "C:\Users\Hp\PycharmProjects\pythonProject\open a file.py" File "C:\Users\Hp\PycharmProjects\pythonProject\open a file.py", line 7 file = open(filepath), ‘r’) ^ SyntaxError: unmatched ‘)’ Process finished with exit code 1 >Solution : From the… Read More I don't know how it is an unmatched )
I am trying to open a file, which I save before, in the program. Then I want to write some text, into the file. But it gives me the following Error, I have already looked for solutions in google and also here on stackoverflow, but the solutions didn’t work. OSError: [Errno 22] Invalid argument: "<_io.TextIOWrapper… Read More How do I write a File in python, with a variable as a path?
I have a script that opens a prompt window for a user to select a directory before performing some other tasks. If the user selects "Cancel", I want the program to display an appropriate message and exit the program. However, I cannot get this to work. Here is what I’ve tried: import tkinter as tk… Read More Catching "Cancel" in Tkinter