Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyInstaller Tkinter window low resolution in App bundle, but not in app program

I think I'm missing something obvious but I can't figure it out myself.

I'm building a Mac App from Python 2.7 using PyInstaller (running the dev3.3 version). The app works fine, no issues. At the beginning there's a small window for updates which is built using Tkinter.

After building the app with PyInstaller (running the oneflie option) I get two files( ls -al outcome):

-rwxr-xr-x   1 karoldra  staff  62756614  8 lis 11:08 mac
drwxr-xr-x   3 karoldra  staff       102  8 lis 11:09 mac.app

Here's the structure of that folder:

  • mac
  • mac.app
    • Contents
      • Frameworks
      • Info.plist
      • MacOs
        • mac
      • Resources
        • MyIcon.icns

Basically - the mac.app package contains exactly the same mac file as the main folder.

The issues is that I get a different resolution in my Tkinter window depending on which file I actually run. Here's a sample of the Tkiter window:

  • the top one is run from the mac file
  • the bottom one is run from the mac.app file

enter image description here

As you can see the bottom ones resolution is much lower for some reason...

Can somebody tell me why this is happening and how to solve this issue?

like image 629
user1544500 Avatar asked Nov 08 '16 10:11

user1544500


People also ask

Does Tkinter work with all versions of Python?

Executed 'tkinter._text ()' in a shell and it appears to work fine. All my uses of tkinter also appear to work fine under all versions of 3.5 under normal use of python. Only tkinter problem I'm having is with PyInstaller. Verified the exact version of Tcl/Tk installed with 'tkinter.Tcl ().eval ('info patchlevel')' and it reported '8.6.4'.

How to measure screen resolution with Python Tkinter?

The second method is the use of the ctypes Python library. This following setting in the ctypes library sets “DPI” awareness. DPI stands for Dots per inch, another way of measuring screen resolution. Keep in mind this will also effect the size of the tkinter window.

How to increase pixel density In Tkinter window?

Keep in mind this will also effect the size of the tkinter window. Basically, you increasing the pixel density by increasing scaling, hence you will have to increase the number of pixels to maintain the same size as before. Adjust the value in the brackets to see what suits your screen the best.

Can I run a Tkinter GUI battleship game on Mac OS X?

I have a Tkinter GUI battleship game application I wrote that I am trying to convert to a .app file so I can run it easily on Mac OS X computers. After cd ing to the directory with both the main .py file, and all the subfiles (three other python files, a json file, and an icon file), I am executing the following command:


1 Answers

Eventually I found the answer by...carefully reading the docs ;) There's this one line which solve my problem:

For example, when you use PyQt5, you can set NSHighResolutionCapable to True to let your app also work in retina screen

In case someone else is seeing this problem on MacOs here's the answer:

My spec file was missing the High Resolution setting specified by the info_plist parameter. Here's an example:

app = BUNDLE(exe,
     name='myscript.app',
     icon=None,
     bundle_identifier=None
     info_plist={
        'NSHighResolutionCapable': 'True'
        },
     )

Hope it will help someone else too!!! :)

like image 129
user1544500 Avatar answered Oct 20 '22 20:10

user1544500