0
votes

I currently have a python script which launches a tkinter GUI instance, with a button that once clicked takes a screenshot.

When I run this script under python.exe, the tkinter resolution is fine and the screenshot captures the whole screen. However, when using pythonw.exe, the tkinter window resolution changes (button gets bigger for example) and the screenshot only captures a portion of the screen - the top left hand corner normally.

I need to use pythonw.exe in order to prevent the console window appearing.

Does anyone know why the tkinter window resolution and the screenshot capture is being effected? Presumably the effect on the resolution is why the screenshot capture is being reduced as well.

I am fairly new to Python, so any help with this would be greatly appreciated, below is snippet of the code for the tkinter window and the screenshot functionality. To reiterate this functionality runs completely fine under python.exe.

The screenshot functionality using ImageGrab:

    callback1():
         ImageGrab.grab_to_file('test.png')

The tkinter window:

    master = Tk()  
    master.wm_attributes("-topmost", 1)
    master.title("Report")
    master.configure(background='white')
    master.iconbitmap(default='icon.ico')
    master.resizable(0, 0)
    frame1 = Frame(master, bg='white')
    frame1.pack(side=BOTTOM, fill=X)
    button1 = Button(frame1, compound=BOTTOM, width=307, height=82,
    image=photo1, bg='white', command=callback1)
    button1.pack(side=TOP, padx=2, pady=8)
1

1 Answers

1
votes

I have now fixed this. It seems it was related to the compatibility settings for pythonw.exe in Windows. Changing the following fixes the image capture, but also the tkinter window resolution:

  • Go to your python directory (c:/python27/ for me)
  • Right click python.exe and select properties
  • Select the compatibility tab
  • Press the "Change settings for all users" button
  • Check the "Disable display scaling on high DPI settings" box

Credited by this post:

Python Imaging Library fails to grab whole screen

Hopefully this helps someone with the same issues. It does beg the question as to how this can be done automatically, as for users of a python application it is not user-friendly for them to have to change these settings.