Skip to content
Related Articles

Related Articles

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:

ArgumentsUses
pdf_location = “location of your PDF”To add your location of PDF.
width = 0 To set the width of PDF Frame.
height = 0To set the height of the PDF Frame.
bar = True or FalseTo hide or unhidden the loading bar.
load = after or beforeTo decide that, when your pdf object is to convert.

Below is the implementation:

We are using this pdf for demonstration:



Code:

Python




# Importing tkinter to make gui in python
from tkinter import*
  
# Importing tkPDFViewer to place pdf file in gui.
# In tkPDFViewer library there is
# an tkPDFViewer module. That I have imported as pdf
from tkPDFViewer import tkPDFViewer as pdf
  
# Initializing tk
root = Tk()
  
# Set the width and height of our root window.
root.geometry("550x750")
  
# creating object of ShowPdf from tkPDFViewer.
v1 = pdf.ShowPdf()
  
# Adding pdf location and width and height.
v2 = v1.pdf_view(root,
                 pdf_location = r"location"
                 width = 50, height = 100)
  
# Placing Pdf in my gui.
v2.pack()
root.mainloop()

Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :