I would like to give users of my simple program the opportunity to open a help file to instruct them on how to fully utilize my program. Ideally i would like to have a little blue help link on my GUI that could be clicked at any time resulting in a .txt file being opened in a native text editor, notepad for example.
Is there a simple way of doing this?
To read a text file in Python, you follow these steps: First, open a text file for reading by using the open() function. Second, read text from the text file using the file read() , readline() , or readlines() method of the file object. Third, close the file using the file close() method.
By using Notepad and the Python interpreter, a programmer can write Python programs and execute them, or create "batch" files that can execute multiple programs, including Python scripts.
Also if you open Python tutorial about reading and writing files you will find that: 'r+' opens the file for both reading and writing. On Windows, 'b' appended to the mode opens the file in binary mode, so there are also modes like 'rb', 'wb', and 'r+b'.
import webbrowser webbrowser.open("file.txt")
Despite it's name it will open in Notepad, gedit and so on. Never tried it but it's said it works.
An alternative is to use
osCommandString = "notepad.exe file.txt" os.system(osCommandString)
or as subprocess:
import subprocess as sp programName = "notepad.exe" fileName = "file.txt" sp.Popen([programName, fileName])
but both these latter cases you will need to find the native text editor for the given operating system first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With