Recently, I’ve been using pygame and found out when I create a window using pygame.display.set_mode((0, 0), pygame.FULLSCREEN), it's shown in the wrong resolution. I have a 2560 × 1600 monitor, but the window is at 1440 × 900 (It's still fullscreen, but the image quality has been reduced).
It's been shown in the docs for pygame.display, I believe that the problem is caused by stretching:
Some display environments have an option for automatically stretching all windows. When this option is enabled, this automatic stretching distorts the appearance of the pygame window. In the pygame examples directory, there is example code (prevent_display_stretching.py) which shows how to disable this automatic stretching of the pygame display on Microsoft Windows (Vista or newer required).
and this answer to a similar question, shown that in windows the problem can be solved using the code below:
ctypes.windll.user32.SetProcessDPIAware()
true_res = (windll.user32.GetSystemMetrics(0),windll.user32.GetSystemMetrics(1))
screen = pygame.display.set_mode(true_res,pygame.Fullscreen)
Sadly, I don't know how to do a similar job in macOS.
I've been able to work this problem out in the fullscreen mode using the code below:
screen = pygame.display.set_mode((2560, 1600), pygame.FULLSCREEN | pygame.SCALE)
Still don't know how to solve this under other circumstances, so I remain the question open.
you can maybe ask the user what his resolution is from a drop-down menu and save that variable in a text file then set the screen width and height to the contexts of that text file
Related
I wrote an Tool with a wxPython GUI. On Full HD and less everything runs fine. A friend of mine tested a bit with my tool and he uses a Microsoft Surface Book laptop with a screen resolution of 3000x2000 and DPI set to 200% on Windows 10.
And he has the problem that everything in my GUI is very small.
I tried to prevent that with this piece of code:
import ctypes
try:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
except:
pass
But that didnt help at all. Does anybody have experience with a problem like that? What else could i try?
I think there is already a question similar to this in Stackoverflow. Anyway.
So far I think the only thing you can do is to set the app to use System (Enhanced) in the High DPI scaling override box.
It does not matter if you do not have a .exe file. You can change the properties of the resulting python app window when you run it as python myApp.py.
If the picture is not enough, there are more details in the first question here.
I have developed a python app with Tkinter on a Mac. It involves forms, and canvas drawings. On the Mac, it looks great. However on my Dell laptop (4K display, and more powerful than my Mac), the Tkinter ui appears very pixelated and certain elements are located slightly differently. What is this problem known as and what can I do to render Tkinter better on Dell Windows 10 or other platforms in general?
Here is a screen shot of the same part of the UI (showing form and canvas drawing)...
Windows(bad)
Mac(normal)
Antialiasing is only enabled for Tkinter canvas object in OSX . You can get the aggDraw lib: http://effbot.org/zone/tkinter-aggdraw.htm as a workaround, but otherwise you will get jagged lines when trying to draw on a canvas. Fonts however should be anti-aliased on all major platforms.
The differences in the display of the same application are due to differences in render engines used by each Operating system.
This is coverd in a Pakt pub ebook called Tkinter GUI Application Development Blueprints
passage regarding this topic available here.
It may be a pain to do but it looks like the most common fix for this is to detect your enviroment and write independent styles using the external option database
more info is available in the documentation here.
Setting your DPI awareness to 1 should resolve your issue
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
Consider the resolution of the MAC as 1366x768 (expected),Suppose you are making your application windows size as 683x384 which is equal to (1366/2 x 768/2).
When the application will be run on a 4k Display it will display the dimensions as 683x384 for the main window but its dimensions on the 4k will be 4k/2.
So what you can do it write a general program with variable dimensions of the screens ,So that it will adjust its window size according to the screen size.
For more details refer to the https://www.tutorialspoint.com/python3/python_gui_programming.htm
Hope this will help.
I am using VPython to visualize some data from a computer simulation.
I want to make a movie out of the VPython output. Therefore I tried to make screenshots from the vpython output window. I want to capture the output window in fullscreen mode. This way i don't need to crop the window frame. I tried ImageGrab.grab() (see here) and win32gui (see here), but both methods capture the desktop instead of the fullscreen window.
Methods screenshot and _get_windows_bytitle from here
windowtitle = 'sometitlename'
newscene = display(fullscreen=True,title=windowtitle)
newscene.cursor.visible=false
newscene.select()
b = box()
rate(1)
screenshot(_get_windows_bytitle(windowtitle)[0])
Same problem with ImageGrab.grab. Any suggestions?
I couldn't find any solution, so I used the workaround by cropping the window manually.
disp = display(width=1000, height=1040)
displayrect = (int(round(disp.x))+8, int(round(disp.y))+30, int(round(disp.width))-16, int(round(disp.height))-38)
ImageGrab.grab(displayrect)
I am not really happy with that, since it's quite messy to hardcode the window border width/height (I won't use the win32 module for that)
I'm developing a screen shot utility in Python. At the moment it is specifically for Linux. So far I have the ability to take a screen shot of the full desktop, and have it upload to Imgur, then copy the link to clipboard. Now I want to expand into functions such as screen shots of the active window, or of a specific selection. If anyone could help, I'd love to know what kind of module would work best for this, and how to implement such a module.
The functionality will depend on what you are using for image grabbing.
With PIL
http://effbot.org/imagingbook/imagegrab.htm
With GTK
To take a screenshot of active window :
http://faq.pygtk.org/index.py?req=show&file=faq23.039.htp
Also look at the pixbuf api
http://library.gnome.org/devel/gdk-pixbuf/
http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html
Off topic
There are some screen cast tools: http://pypi.python.org/pypi/castro/1.0.4
I'm writing a python script that runs in the background and takes screenshots of another application that is active. Then it analyses the screenshots and now it should overlay a certain image over the active app or the screen. I still need to be able to make mouse and keyboard inputs in the active app.
So I need a way to overlay/paint on another window or on the screen, and still keep the other window the active window so that I can make inputs.
I would prefer to do that with python in Mac OS, but if it isn't possible, other languages and even Windows (if really necessary) would also be ok.
Can anybody help me?
Thanks in advance!
http://www.michaelfogleman.com/2009/12/drawing-on-the-windows-desktop-using-python-and-wxpython/
Seems to do what you want, but is windows only, as are some other answers to similar questions here on stackoverflow