I have the same problem as here: Screen displays only in top left corner of window
The pygame container is messed up by the high resolution retina screen. I have searched around and haven't found any one with an answer other than "change your resolution".
Is it possible to fix this in the game, so that the player doesn't have to fix it themselves? Either fixing the bug in pygame or resizing the resolution when the game starts? Maybe it could work only in fullscreen somehow?
TO CLARIFY: I don't want to have to change the screen resolution manually, but within the pygame-code.
I don't know if you've figured this out at all yet as it's been a while. But you can enable low resolution mode for the pygame window in the Macs application settings. Then you don't have to change your resolution every time. I still haven't figured out how to fix this in code though.
https://support.apple.com/en-us/HT202471
Edit: I'm assuming it's a Mac you're using.
I am afraid there isn't any way. pygame hasn't been updated for a while and I think development has stopped. I ran into the same problem and ended up dealing with using a program called setresx when necessary. The problem can also be fixed by hooking up your computer to an external monitor. I know you can get some portable ones that you can put on the side of your screen.
As to changing the code, as far as I'm concerned it isn't pygame that there is anything wrong with, but technically the screen. That said, you might be able to change the library itself to handle the issue.
Related
I wrote a music player in Python using Pygame and Pydub(I used Pygame for actually playing the music, while Pydub is probably unrelated to the issue).
The music works fine even when windows are switched unless I switch to another Pygame window. I thought this effect would go away if I compiled it(cx_freeze), but that didn't work.
So I was wondering if there is any way to let the music keep playing when the window is switched to another Pygame window.
I used pygame.mixer.music instead of Sound objects if that might somehow be related.
Thanks in advance!
Not exactly a fix, but it seems that if I disable the mixer(pygame.mixer.quit()) it doesn't cancel out the audio. Unfortunately, I haven't found a way to use audio in two pygame windows at once.
Feel free to post another answer if anyone figures out a full fix.
Is there a way to control screen brightness through Python? For example, I'm using Tkinter right now, and I'm wondering if there is a way I can program a button in tkinter to increase the brightness of the screen (and make another button that decreases the brightness of the screen)?
EDIT: I'm using a Windows computer, it's on Windows 10, but I also need it to work on Windows 7 too.
I used the WMI library and it really worked fine. Here is the code, but this is for Windows. I think it is OS specific so if it doesn't work for you, you should look for a better solution.
import wmi
brightness = 40 # percentage [0-100] For changing thee screen
c = wmi.WMI(namespace='wmi')
methods = c.WmiMonitorBrightnessMethods()[0]
methods.WmiSetBrightness(brightness, 0)
In tkinter you will not be able to adjust screen brightness. You might be able to make a macro and have your python program access it. Also with desktop monitors brightness is set by the monitor so depending on your model you will probably not be able to make any change at all. Good luck :)
Here is a link on using macros. Check it out and maybe find a way to control screen.
Pressing command-H in OSX immediately hides the active window. How do I achieve the same effect, programmatically, from Python? Specifically, I'd like to find a particular window that my application creates and then be able to show & hide it programmatically.
I already know how to do this with pywin32 but I'm afraid my expertise there doesn't quite cover OSX as well.
If it helps, the window in question is one created by pygame. I know that pygame has pygame.display.iconify() but that doesn't satisfy my requirements - the window doesn't disappear immediately, but rather the disappearance is animated, and there's no corresponding "uniconify" function that I can find.
Well, this ended up working. When I want to hide the window, I do pygame.display.quit() and make my code properly handle not having a display. When I want to show it, I do pygame.display.set_mode(...) with the former resolution.
The net effect is that of hiding & showing the window. Unfortunately the window gets created in a different spot than where it started, and although apparently you can tell SDL to create the window in a particular spot, I haven't been able to find a way to get the window's location...
i am using python/tkinter to write a IM software on XP. now i've got all the main functions done except i don't know how to highlight or change colour my IM item on taskbar on windows xp when window is minimized to the taskbar when a new message is received. i've search for this but just got c# solution. i need help on python. thanks!
I needed to do this for a tkinter python slack client I am writing and found http://wiki.tcl.tk/1049 . After a bit of guessing, I found that
Tk().deiconify()
Tk().focus_force()
(i.e. on the root window) does the trick. Windows doesn't actually change the focus and show the window since applications are not allowed to do that (Windows after XP) but it flashes the taskbar instead. It will keep flashing until clicked on but that seems to be the behaviour of Skype/Slack etc. Certainly close enough for many uses.
Obviously this is an old question but I couldn't find a concise, python only, answer and still needed one!
I'm not sure if there is a good way of doing this with Tk. Maybe somebody more knowledgeable will be able to point you in a better direction. Since Python is so dependent on OO, you may have a difficult time writing bindings to the Windows window manager.
If you don't find anything else, I did stumble on http://wiki.tcl.tk/4089, which manages Windows icons on the taskbar. Perhaps you could utilize this to simulate the taskbar flash that you want?
Is there any way I can create a UAC-like environment in Python? I want to basically lock the workstation without actually using the Windows lock screen. The user should not be able to do anything except, say, type a password to unlock the workstation.
You cannot do this without cooperation with operating system. Whatever you do, Ctrl-Alt-Del will allow the user to circumvent your lock.
The API call you're looking for Win32-wise is a combination of CreateDesktop and SetThreadDesktop.
In terms of the internals of Vista+ desktops, MSDN covers this, as does this blog post. This'll give you the requisite background to know what you're doing.
In terms of making it look like the UAC dialog - well, consent.exe actually takes a screenshot of the desktop and copies it to the background of the new desktop; otherwise, the desktop will be empty.
As the other answerer has pointed out - Ctrl+Alt+Delete will still work. There's no way around that - at least, not without replacing the keyboard driver, anyway.
As to how to do this in Python - it looks like pywin32 implements SetThreadDesktop etc. I'm not sure how compatible it is with Win32; if you find it doesn't work as you need, then you might need a python extension to do it. They're not nearly as hard to write as they sound.
You might be able to get the effect you desire using a GUI toolkit that draws a window that covers the entire screen, then do a global grab of the keyboard events. I'm not sure if it will catch something like ctrl-alt-del on windows, however.
For example, with Tkinter you can create a main window, then call the overrideredirect method to turn off all window decorations (the standard window titlebar and window borders, assuming your window manager has such things). You can query the size of the monitor, then set this window to that size. I'm not sure if this will let you overlay the OSX menubar, though. Finally, you can do a grab which will force all input to a specific window.
How effective this is depends on just how "locked out" you want the user to be. On a *nix/X11 system you can pretty much completely lock them out (so make sure you can remotely log in while testing, or you may have to forcibly reboot if your code has a bug). On windows or OSX the effectiveness might be a little less.
I would try with pygame, because it can lock mouse to itself and thus keep all input to itself, but i wouldn't call this secure without much testing, ctr-alt-del probably escape it, can't try on windows right now.
(not very different of Bryan Oakley's answer, except with pygame)