0

I need a button which the user can click which will open a textfile called "project tkinter.txt" (which is already existing).

I tried this suggestion another user had:

def opencopypaste():
    from os import startfile
    startfile("c:\\path\\to\\file") # i put the file path here #

openbutton = Button(frame, text='click me', command=opencopypaste)
openbutton.grid()

However, it says it cannot find "startfile" in os.py. Then I tried another suggestion which was:

def opencopypaste():
    webbrowser.open("project tkinter.txt")

This time the code ran and created a button, however clicking on the button did nothing. I can't seem to find any way to create a hyperlink or button to a textfile in tkinter. Help would be much appreciated!

Joshua Hall
  • 332
  • 4
  • 15
  • 1
    Does this answer your question? [Is there an platform independent equivalent of os.startfile()?](https://stackoverflow.com/questions/17317219/is-there-an-platform-independent-equivalent-of-os-startfile) – Scratte May 03 '20 at 06:29

1 Answers1

0

Are you working on Mac or Linux? Because if it is the case this question could be helpful.

  • yes i am, and that question completely solved my problem! thank you so much! for some reason i never saw that, thank you so much for sharing! – user13445224 May 03 '20 at 04:41