Why is TKinter restricted to a specific resolution? - python

I have been using an edited version of the graphics.py library by John Zelle which is based upon TKinter for some time now, but this question always confused me:
Why is the resolution of the screen (the pixels/unit) of the TKinter screen lower than my computer's?
Now what I mean by this is, if I draw a point on window like so:
the pixel is VERY clearly visible. However, I know for a fact that my computer can display higher resolutions (obviously). When I use a vector graphic editing software, I can't make out individual points on the window - so why can I over here. How much ever I have tried increasing the resolution of the window, the pixel size remains the same.
The size is very different to if I used vector graphics - If I had a curve, I would see a curve, not some anti-aliased pixels. So why is this? Why can't I draw smaller pixels on a TKinter screen?
The same thing happens with PNG Images - Why can't I export in a higher resolution so that I don't see any of the anti-aliasing (yes the size would increase, but why isn't the option available), why is this a limitation when I can clearly see that it is not when I am using vector graphics?
Vector graphics can be zoomed in infinitely, but that is not my point. My question is if my computer's screen is capable of displaying far higher resolutions than what I can in TKinter, why can't I display them?

Related

Is there a way to make the python-vlc window acknowledge cropping?

I want to play a video using python-vlc. I have gotten everything to work, and the video plays without any technical issues. There is this one aesthetic issue, though. I only want to play part of the video. As in, I want to crop out a fair bit on the bottom and a good bit on the right. I know I can do this with a call to MediaPlayer.video_set_crop_geometry(), and I've done so semi-successfully. However, the actual window that opens is the one that is adjusted for the entire video, with the part that I want centered in the middle with black bars around it. (If I call MediaPlayer.video_set_scale(), then the cropped-out bit the same size as it would be if I didn't crop. If I don't call video_set_scale(), the cropped-out bit is stretched, maintaining aspect ratio, until it reaches the edge of the window. Regardless, there are black bars).
Can I get the window to adjust to this new, smaller video? Preferably automatically, but if I have to pass in the size I want, that's fine too.
I have tried shuffling around the order between the different calls to no avail. Clearly python-vlc has the capacity somewhere to adjust the window it's playing in, as it can open a window the correct size for the regular video to play, and it adjusts automaticallty after calling video_set_scale(), but only to fit the original video, not the cropped one.
You should probably share more details, such as your full code and platform used.
That being said, libvlc doesn't offer an API to resize the native Window it draws on, but you can easily do it yourself (with win32 APIs for HWND, on Windows, for example).

Adding a vertical and horizontal scroll bar to the display surface in Pygame

I'm using pygame and I've been working so far in a large monitor, but now I need to work on a small laptop, whose screen is much smaller than the mentioned monitor. The dimensions I gave to the display surface and the items blitted to it work well on the previous monitor but it is too large on the laptop and therefore I cannot reach all buttons. Since I can't seem to find a way to resize everything proportionaly, is there an easy way to add a vertical and horizontal scroll bar in order to navigate around the display surface?
Thank you
I don't think that you can add a scroll bar. What you can do is shift the x or y of everything when you press the corresponding arrow keys. But as said by Ted Klein Bergman, it is better to simply resize everything.

Overlay all screens and draw rectangle with a mouse

I am working on tiny program to capture screen print, I want to do it in a similar fashion that Win Snipping Tool is working. First I need to overlay all screens with a 50% opacity layer and then, using the mouse, draw a rectangle and read vertices coordinates. Honestly, I have no idea how to bite this. I tried with win32api / gui and it is great to get mouse coordinates, but still was unable to draw a rectangle. My idea (one of many) is to (using PIL / ImageGrab) take shots of both displays, put an overlay and print them as a full screen on all windows, but I failed while doing this. Other idea is to take img grab and create two new windows using BeeWare / Toga (that is GUI framework I am using) in full screen, but I was unable to find any method to open window on second display. Any ideas and hints will be greatly appreciated, I am really counting on you, as I feel I reached dead end.
Well,It is very easy to use tkinter.
Ok,It is the principle when I make my screenshot application:
User presses the button to start.
Make a new window whose width and height should full cover all the screens,and hide the title bar(If it is had to achieve,maybe use width=9999 and height=9999).
Take a screenshot of all the desktop(You can use ImageGrab.grab((),all_screens=True)) to do that.
Make the screenshot showed in a Canvas(I know that toga have this widget).
Start your mouse listener thread and save the position of pressed.
When user moves his mouse,create a rectangle(toga's Canvas have a function rect()).Maybe use this rect(pressed_x,pressed_y,move_x,move_y).And delete the last rectangle(Then it will always show only one rectangle).
When user released his mouse,save the position of released.And use ImageGrab.grab((pressed_x,pressed_y,released_x,released_y),all_screens=True) to crop the selected area.
If you want to show it in application interface.toga has a widget called ImageView.You can put the image in it.

Python background program to modify Windows screen resolution, shape?

I'm looking to make a Python program, that while running in the background (e.g. started through command line), will change the screen resolution of Windows (and shift the screen position). And then the user is free to continue to use their computer in this different resolution.
E.g.: (fake code below)
import os
os.changeResolution(800,600)
# the entire windows desktop resolution changes to a (800,600) box, with black/empty around it
os.changeScreenPosition(100,200)
# shifts the (800,600) window of the desktop to position (100,200)
while 1:
# do nothing, just keep the screen like we set it above while this little python program is running somewhere
continue
Picture below showing before/after:
after:
(screen is shrunk to new resolution, position is offset, background surrounding is black)
Now while this program is running minimized somewhere the user can go about their other desktop tasks. Is this possible with Python and Windows 10?
As a follow-up, what if I wanted to change the shape, from say a rectangular box, to a circle? E.g. to distort / bulge the screen.
Resizing the window will only make it fill your monitor at a lower resolution.
You can mess about with the magnify function to make it larger or live copy an area at the same resolution.
You can use thumbnails (the way windows 10 shows a preview when you hover over a window in the task bar) to make it look smaller, but it won't pass control to a smaller window.
Both are by the DWM (Desktop Window Manager) and don't let you intervene with the image short of adjusting the colour (magnify can tint the window or make it black and white)
Distorting to a round window is a whole can of worms. There are a few options explored in my old post below. I've still to give it a go, when I get some time, but think I'll be going down the route of trying to hook into DWM.
Realtime video processing for the complete Windows desktop

Prevent image stretch in fullscreen for psychopy

This is the first time I am using this software to create an experiment.
For my experiment I am presenting two images side by side, ideally I would like to run this experiment in fullscreen but when I set the value to true, the images become stretched. How do i fix their aspect ratio so I can run the program in full screen without stretching the images?
I am using a MacBook Pro and the PsychoPy coder.
Here is my current code for the images:
scale=0.7
faceRGB = visual.ImageStim(win,image='male.jpg',
mask=None,
pos=(0.0,0.0),
size=(scale,scale))
faceRGBINV = visual.ImageStim(win,image='maleInv.jpg',
mask=None,
pos=(0.0,0.0),
size=(scale,scale)`
Furthermore, in my experiment one of the images will be slightly compressed or stretched as it is. The participants will then have to choose the fatter face. This is already set up and when run in a window the images appear normal, it is just in fullscreen mode when they become stretched to fit the monitor size.
By default, PsychoPy uses 'norm' as units, which is size normalized to the window dimensions. You may have a situation where you (1) change the size of the image and (2) the image just happens to have the correct dimensions when presented in the default 800 x 800 pixels Window but appears stretched when you go fullscreen because your monitor has another aspect ratio.
If you don't change the size of the image, PsychoPy maintains the correct aspect ratio. Scaling the image will preserve this aspect ratio, so that's an easy solution. E.g. add one line after initiating the ImageStim:
scale = 0.7
from psychopy import visual
win = visual.Window(fullscr=True)
faceRGB = visual.ImageStim(win, 'male.jpg')
faceRGB.size *= scale # scale the image relative to initial size
If you want to control size directly and not just proportionally, see this discussion on the users list. I suggested the following solution. Say you want to set the image size so that scale is the maximum length along either the x- og y-axis and scale the other axis proportionally. Replace the last line above with this:
faceRGB.size *= scale / max(faceRGB.size)
Multiplying maintains aspect ratio as above and the righthand side is the multiplication factor to ensure scale. Change max to min if you want this to apply to the minimum length instead of the maximum length.
Note: you do not need to set pos=(0,0) and mask=None as that is the default value of these parameters.

Categories