i wanted to make a caps-lock and num-lock indicator using python on windows,
but i dont know how to start with and what all modules and library i need to implement my desired output.
THE OUTPUT i desire is that whenever i press CAPS-LOCK the borders of screen should go green and for *NUM-LOCK** blue.
also, does it require a GUI?
(but i want it to be transparent. i don't want minimise,close and maximise buttons on gui) and this all process should be done in background.
Please guide me on how should i approach this.
THANKS A LOT.
There's the WinApi package for python here.
Not very well documented, but after quick look at demos looks like this code works:
import win32api
import win32con
print(win32api.GetKeyState(win32con.VK_CAPITAL))
For green frame you'll need probably some GUI library (GTK+, Qt), but I don't know which one could achieve such effect.
Edit: I figured you can actually use the same WinApi to draw on the screen.
import win32api
import win32gui
import win32con
pen = win32gui.CreatePen(win32con.PS_SOLID, 7, win32api.RGB(255, 0, 0))
dc = win32gui.GetDC(0)
win32gui.SelectObject(dc, pen)
win32gui.MoveToEx(dc, 0, 0)
win32gui.LineTo(dc, 1920, 0)
Related
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.
I have a window that can't be minimized.
I have to prevent users to access it while the gui automation.
How to handle this kind of problems with pywinauto?
It works with autoit and the WinSetTrans() function.
Is there something similar in the pywinauto module?
There is no such method in pywinauto, but it's easy to implement. Thank you for the feature request!
So far you may workaround it so:
import win32gui, win32api, win32con
hwnd = app.dlg.ctrl.handle
ex_style = app.dlg.ctrl.ExStyle()
win32gui.SetWindowLong (hwnd, win32con.GWL_EXSTYLE, ex_style | win32con.WS_EX_LAYERED )
win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0,0,0), 180, win32con.LWA_ALPHA)
P.S. It was quickly adapted from the known answer (I didn't check it yet). We will include something like SetTransparent method into pywinauto 0.5.3 (planning this week).
I am working on a RPG game using Python and Pygame, and am trying to make a two-part GUI, including a lower part that is like the basic command line, and a top part that will show all graphical "action."
What I need to find out is a way to include both in a pygame window, instead of using a pygame window and terminal window. As well, are there any Pygame GUI toolkits that would be appropriate for this use?
Thanks All!
May I suggest using ezText instead?
It's a cool way to add text inupt bars to pygame. I used it before my self, and It's really easy to use.
http://www.pygame.org/project-EzText-920-.html
(feel free to leave a comment if you want help using it, although everything you need to know is in the example.py that comes with it)
Take a look here (http://wiki.python.org/moin/PythonGameLibraries) for a whole list of ToolKits for both Pygame and Pyglet. Albow (http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/) has worked well for me in the past.
The easiest way to accomplish what you're talking about would be to make two Surfaces, one for each part of the interface, and then constantly update them in separate modules to finally blit them every frame. That way your main module can be simplified to something like:
import action_gui
import cl_gui
import pygame
pygame.init()
MAIN_SURF = pygame.display.set_mode((x, y))
pygame.display.set_caption('My Game')
while (True):
action_surf = action_gui.update()
cl_surf = cl_gui.update()
MAIN_SURF.blit(action_surf, my_position_1)
MAIN_SURF.blit(cl_surf, my_position_2)
Best of luck.
I'm writing a little program that basically has a bunch of buttons that when you click one, it inputs a certain line of text into an online game I play. It would be a lot easier to use if the GUI would stay on top of the active game window so the user could be playing and then press a button on the panel without having to bring it to the front first.
Any help on how to do this would be great. Thanks
EDIT: Using tkinter
You will need to provide the information on which GUI framework you are using for detailed answer at SO.
On windows you could do something like this with the handle of your window.
import win32gui
import win32con
win32gui.SetWindowPos(hWnd, win32con.HWND_TOPMOST, 0,0,0,0,
win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
Also with Tkinter, you might want to try. I have not tried it though.
root = Tk()
root.wm_attributes("-topmost", 1)
Just wondering if there is any kind of framework or method of making a Gui that will override (Stay on top of) all other windows in python. Including Games or other programs that seem to "Take over" the computers Graphical processes. Any point in the right direction would be much appreciated...
PS. The OS in question is Windows 7, but a cross platform solution would be appreciated.
You need the SetWindowPos function from the Win32 API. Something like the following should work (see the API link for more details):
import win32gui, win32con
hwnd = get_my_window_handle()
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
For a cross-platform solution, you could use wxPython with a wxSTAY_ON_TOP style bit in a main window. I believe that this will give you the behavior you desire on Mac and Unix GUIs as well as Microsoft Windows ones.