pythontkinterequivalent

equivalent code of 'open with' in python script


open a file in python tkinter app

import sys
sys. argv[1]

is the code equivalent of the above image. Please reply me


Solution

  • finally i got the answer. yes it is right I wanted to create a pdf reader application using python tkinter which i will use to open any pdf file. When i will click a pdf file it will show my tkinter app and i will open it via my pdf app this tkinter app will show that pdf file.And finally i successfully completed it. This is full code

    from tkinter import *
    from tkinter import filedialog
    from tkPDFViewer import tkPDFViewer as pdf
    import os
    import sys
    
    root = Tk()
    root.geometry('630x700+400+100')
    root.title('Python Pdf Reader')
    root.configure(bg='white')
    try:
        filepath = str(sys.argv[1])
    
    except:
        filepath = ''
    v2 = pdf.ShowPdf().pdf_view(root, pdf_location=filepath,
                                width=77, height=100)
    
    
    def browseFiles():
        global v2
        try:
            filename = filedialog.askopenfilename(initialdir=os.getcwd(),
                                                  title="Select pdf file",
                                                  filetypes=(('PDF File', '.pdf'),
                                                             ('PDF file', '.PDF'),
                                                             ('All file', '.txt')))
    
            v1 = pdf.ShowPdf()
            v1.img_object_li.clear()
            v2.destroy()
            v2 = v1.pdf_view(root, pdf_location=filename,
                             width=77, height=100)
            v2.pack(pady=(0, 0))
    
        except Exception as e:
            print(f'{e}')
    
    
    Button(root, text='Open', command=browseFiles, width=40, font='arial 20', bd=4).pack()
    
    v2.pack(pady=(0, 0))
    
    root.mainloop()
    

    And when you will build this code into windows installer and install this in your windows pc. You will get that result. This is my details answer so share this answer. I think it will really help anybody