How to add PDF in Tkinter GUI Python ?
Last Updated :
13 Jan, 2021
In this article, We are going to see how to add a PDF file Tkinter GUI, For that, we don’t have a direct widget to do this. For that, We need to have python version 2.7 or more. And you need to install the ‘tkPDFViewer‘ library. This library allows you to embed the PDF file in your Tkinter GUI.
Installation:
To install this library you just have to type:
pip install tkPDFViewer
Approach:
- Initialize tk and geometry of our GUI.
- Import tkPDFViewer.
- Make the object of Class ShowPdf() from tkPDFViewer.
- Using pdf_view method from ShowPdf() to place our pdf.
- Pack the pdf_view in GUI.
Arguments of method pdf_view:
Arguments |
Uses |
pdf_location = “location of your PDF” |
To add your location of PDF. |
width = 0 |
To set the width of PDF Frame. |
height = 0 |
To set the height of the PDF Frame. |
bar = True or False |
To hide or unhidden the loading bar. |
load = after or before |
To decide that, when your pdf object is to convert. |
Below is the implementation:
We are using this pdf for demonstration:
Code:
Python
from tkinter import *
from tkPDFViewer import tkPDFViewer as pdf
root = Tk()
root.geometry( "550x750" )
v1 = pdf.ShowPdf()
v2 = v1.pdf_view(root,
pdf_location = r "location" ,
width = 50 , height = 100 )
v2.pack()
root.mainloop()
|
Output:
Share your thoughts in the comments
Please Login to comment...