EmaSMach

"Open with"

Jul 15th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # a simple code to show how to open a file by:
  2. # "open with" context menu option.
  3. # "drag" and drop a text file on the .exe file
  4. # .exe built with pyinstaller
  5. # author: David Emanuel Sandoval
  6.  
  7. from tkinter import *
  8. from tkinter.scrolledtext import *
  9. import sys
  10.  
  11. def main():
  12.     root = Tk()
  13.     text = ScrolledText(root)
  14.     text.pack(expand=YES, fill=BOTH)
  15.     root.mainloop()
  16.  
  17. if __name__ == '__main__':
  18.     try:
  19.         f = open(sys.argv[1])
  20.         content = f.read()
  21.         f.close()
  22.         root = Tk()
  23.         text = ScrolledText(root)
  24.         text.insert(0.0, content)
  25.         text.pack(expand=YES, fill=BOTH)
  26.         root.mainloop()
  27.  
  28.     except:
  29.         main()
Advertisement
Add Comment
Please, Sign In to add comment