1

I'm writing a code to open a PDF file, select the number of pages to crop, and then create a new cropped file.

Here is the code:

from easygui import *
from pyPdf import PdfFileReader, PdfFileWriter

# 1 select a inputfile
inputFileName = fileopenbox('Please choose a PDF file','', '*.pdf')

#2 total pages
inputFile = PdfFileReader(file(inputFileName, 'rb'))
totalPages = inputFile.getNumPages()

#3 Enter  beginning Page  
begPage = enterbox('Please choose the Beginning Page','it must a number')
while not begPage.isdigit() or begPage ==0 or int(begPage) > totalPages: 
    msgbox('Please enter a valid digit', '', 'ok')
    begPage = enterbox('Please choose the Beginning Page','it must a number')

The thing is while testing these first steps. When I select the file and click OK, the fileopenbox freezes, and I don't get to the next step.

If I isolate the first step or the steps 1 and 2, it works just fine, but I cannot get it working with the rest of the script (step 3).

I'm using Python 2.7.10 on my macbookPro OSX 10.9.2 and easygui 0.97

SiHa
  • 7,830
  • 13
  • 34
  • 43
Ruseiro
  • 23
  • 1
  • 4
  • Your code works just fine for me. Perhaps your pdf is malformed - have you tried multiple files? P.S. `begPage ==0` should be `int(begPage) == 0` Python 2.7.10, easygui 0.97, Win7 – SiHa Dec 03 '15 at 13:02
  • Could be a path issue - is `inputFileName` returning the full path to the document? It does on my system, but OSX may be different. – SiHa Dec 03 '15 at 13:06
  • I've tried with different files, but it still freezes. `InputFileName` returns full path. I have "clicked around" on different things trying to fix the problem, and I found out that if i click on the python icon in my dashboard, the script unfreezes and goes to the next step(2 and 3).... but this only happens with `fileopenbox` , the rest of the boxes prompt out automatically... P.S. Thanks for the `begPage==0` fix. – Ruseiro Dec 03 '15 at 13:19

1 Answers1

1

Easygui uses tkinter for its gui bits.

This page says that (emphasis mine):

If you are using Python from a python.org 64-bit/32-bit Python installer for Mac OS X 10.6 and later, you should only use IDLE or tkinter with an updated third-party Tcl/Tk 8.5, like ActiveTcl 8.5 installed.

If you are using OS X 10.9 or later and a Python from a python.org 64-bit/32-bit installer, application windows may not update properly due to a Tk problem. Install the latest ActiveTcl 8.5.18.0 if possible. (Also, a critical OS X 10.9 problem that could cause Python to crash when used interactively has been fixed as of the 3.4.0, 3.3.3, and 2.7.6 installers.)

If you are using Mac OS X 10.6, do not use IDLE or Tkinter from the Apple-supplied Python 2.6.1 in Mac OS X 10.6. If possible, install and use a newer version of Python and of Tcl/Tk.

This sounds like your problem, so it looks like ActiveTcl is what you require to fix your tk problem.

SiHa
  • 7,830
  • 13
  • 34
  • 43
  • Sorry, but still the same issue... I've finished the whole code, and except the `fileopenbox`box, the rest of boxes pop out as they should... even the `filesavebox` (as opposed to the first one). The script runs perfectly and does what is it meant to do, except for that freezing issue at the beginning. – Ruseiro Dec 03 '15 at 16:36
  • Have you installed ActiveTcl though? The fact remains that your code works on my Windows system but not your OSX one. I'm not saying tat this is definitely the answer, but to discount it out of hand seems a bad idea. – SiHa Dec 03 '15 at 17:24
  • Yes, I have installed ActiveTcl. I tried to run the code on Windows as well and it works... it must be something related with OSX, or even worse, particularly with my computer, which makes it even more difficult to solve... i've tried to run different combinations of EasyGui elements, and they all work fine, except `fileopenbox`... I've tried to run it on IDLE and Terminal, and on both i get the same error. – Ruseiro Dec 04 '15 at 11:33
  • btw, i've installed ActiveTcl, but what should i do next? – Ruseiro Dec 04 '15 at 13:09