Part of the script responsible for minimalizing works just fine, point is, when I want to restore the window it doesnt work. I guess it's because the keyboard input is not sent into my app anymore. Can I fix that somehow? I use Ubuntu. How do I make the app wait for my shortcut no matter where in the system I am at the moment? I would like to make it work, even when I'm on my browser for example.
def minimize(event):
root.wm_state("iconic") # minimize the window
def restore_window(event):
root.deiconify()
root.bind("<Control-z>", minimize)
root.bind("<F11>", restore_window)
I dont know, maybe I should use a different package than tkinter for that kind of software.
Related
Is there a way to get all keyboard input from turtle in python not just specific keys. I am aware I can use turtle.onkey(up, "Up") to call a function on a specific key press but I want to be able to get any key press without having to go through and manually set a function for every single key as I want to be able to display user text input in the turtle window directly without having to use console or alternatives like that.
the answer is no, you can't do it only with turtle, turtle built with tkinter and tkinter don't have that option, if you want to do it you should import other modules like pyinput, but pyinput may not that easy to learn (I didn't really try)
I just use the module "keyboard" (to download it on windows go to command prompt and type pip install keyboard) but I didn't try all of the functions with that module and I don't know if it is fully trusted, I just use it for one simple function which is
from keyboard import is_pressed as pressed
if keyboard.pressed('h'): # just for example it should be a string
# what ever you want to do here
so I really recommended to just learn pyinput cause it is really has more options, but if you don't use a lot of options you can do like me.
I am using pynput to record keystrokes via Listener on OS X Mojave. I am using Pycharm as my IDE for running the code.
I was not able to get it to work using the same example from the pynput site.
from pynput.keyboard import Listener as key_listener
class recorder:
def on_press(self, key):
print(key)
def on_release(self, key):
print(key)
if __name__ == "__main__":
testme = recorder()
with key_listener(on_press=testme.on_press, on_release=testme.on_release) as listener:
listener.join()
I did step through it and I get no errors (unless I put the with statement in a function, instead of in the main, but that's a known issue with threading in Mojave, from what I can tell after searching for that error), but everything stops at the .join() statement, and I get nothing printed when I press and release a key on my keyboard.
This is probably a bit late, but the answer is to go into:
Settings -> Security & Privacy
Click on the Privacy tab
Click the + Hold down CMD + SHIFT + . (so that you can see hidden
files/folders)
Navigate to /usr/local/bin or wherever you have Python installed
Click okay.
That should do it.
Note
If you try to run your app via the terminal, you will need to add the terminal.app to the list of allowed apps, as done above for Python.
Found the problem.
For some strange reasons; OSX is uber-picky about returning events, so unless you go in the security settings and enable Pycharm to be in the list of apps that are allowed to use accessibility, it won't work.
I didn't try on Windows yet, but I assume it will be the same issue. The only gripe I have is that I have no idea how to add Python itself to the list of supported accessibility apps; since the control panel does not allow me to go in /usr/local/bin, which is where I have Python3 installed (via Brew).
This is probably a bit late too, but the simple answer is to go into:
Preference
Security & Privacy
Input Monitoring
-> confirm PyCharm
Some people have stated that adding IDLE to supported accessibility apps is what allows python itself to run the listener.
while your in a finder window, if you press cmd+shft+'.' (period key) it will show hidden files, which will allow you to navigate to usr/local/bin and look for your python implementation.
On windows this is slightly different, I always run python/pycharm as admin and it never gives me any issues.
Try superuser ($sudo su) and run your python code in terminal, I think
it should work
Im was working with OSX 10.12 and pynput was only getting cmd ctrl fn and option keys when pressed but now in superuser it gets the keys.
Intermittent Failures with webdriver.js
I am creating some webdriver.js* scripts to automate some time consuming test setup activities. However, when I run the script and do other things with my keyboard and mouse, I come back and find that, intermittently, a particular element cannot be found. And it's a different element each time.
When I run the same scripts and just watch them run, the scripts execute correctly.
Also, when I researched this potential problem, I came up with lots of stuff on using the mouse in webdriver scripts and problems with the click method itself but couldn't find anything to do with my issue. So I'm wondering whether I'm just doing something wrong here.
So What's The Question?
My question is: Is webdriver.js not meant to run like this? (that is, run locally while the keyboard and mouse are doing other things)?
Webdriver.py?
I don't remember having these problems when I used webdriver.py a few years back. iirc, I was able to run the scripts while the workstation was locked (via Win + L) though my memory isn't what it used to be ;)
I would use webdriver.py, however, no one else in our team knows python so I thought I would go webdriver.js since we all know javascript :)
Params: IE11, Windows 10.
* Also, when I say "webdriver.js", I mean the webdriver that is installed after following the steps here
I found that if I replaced the .click() calls with an equivalent .sendKeys() call (e.g. webdriver.Key.ENTER / webdriver.Key.SPACE) , this would get around the problem. I could even lock my workstation and the scripts would run without any problems.
So, a few months back I made a small GUI for handling NPCs in a roleplaying campaign I was running. I haven't touched in since then, except that now I need it! Tomorrow, in fact...
I have a few odd error... Loading the GUI seems to work fine, but when I start to press buttons the troubles start. It seemed, at first, that it the script was very slow, which it shouldn't be, calling a two line dice function on a button press. I accidentally figured out that when I hover the mouse over the "close/minimize window" buttons (not in the GUI, but in the OS), the button would update with the result of the button press.
The same thing happens with a listbox I have: choosing an item may or may not select the item straight away (but hovering over the close/minimize updates it), and the results of the selection may or may not show. The results is in fact weirder: selecting a listbox item is supposed to get info from the selected item and print it in another frame. Even if the selection itself is fine without hovering, the printed text is somehow "clipped", showing only an area seeming to cover an arbitrarily sized square of text... Remedied by hovering, of course. The rest of the GUI have the exact same problems.
I have no clue what is going on here. The script was written on another computer, but that was also a Mac running the same OSX version (Mavericks), and it was a MUCH slower computer. This script shouldn't need any sort of advanced specs, though! I'm guessing it's something wrong with migrating to the new computer and the various version of different software? I'll paste the script down below, in case that'll help somehow.
Any help would be greatly appreciated, especially if it comes before the next epic campaign of Superheroes starts tomorrow afternoon! =P
[UPDATE]:
It was some time ago, but I still would like to have this problem solved. I've reduced my script to just a simple button, and the problem persists: clicking the button, even though there is no function or anything associated with it, only results in the frozen "button-clicked"-colour (i.e. light blue on OSX Yosemite), and I have to hover my mouse pointer over the close/minimize/etc. buttons in the top left corner to make it go back to "idle-button"-colour (i.e. grey).
#!/usr/bin/python
import tkinter as tk
root = tk.Tk()
test = tk.Button(root, text='test')
test.pack()
root.mainloop()
So, the problem obviously isn't with any of my "downstream" scripting, but something with the module or my way of calling it. Calling the script for the Terminal doesn't give me any error messages, and the problem is still there. Any ideas? It would be really, really good to get to the bottom of this problem!
I had the same problem when using Tk 8.5.13 on Mac OS X Sierra (10.12.3) with Python and IDLE v3.6.0.
Upgrading to TCL/Tk 8.5.18.0 as recommended on the Python Software Foundation page https://www.python.org/download/mac/tcltk/#activetcl-8-5-18-0 seemed to do the trick. This was the recommended version for my edition of the OS.
The interface I was building starting responding as I would expect, i.e. straight away when one of the controls was used. The only reservation I have so far is that normal buttons don't seem to have any sort of animation now, although the buttons do actually work.
-S.
I am working on old Motif-based application for Linux. I want to be able to programmatically change the active window of our application. I can redirect the input by using XSetInputFocus() function and the keyboard input start to go there, but XReconfigureWMWindow() and XRaiseWindow() functions just don't work.
I've read that Window Managers try to stop this behaviour, so tried to disable configure redirection, but this doesn't work either. Any ideas how to make one of my own windows on top of the window stack?
There is a tiny program called wmctrl available (at least in Debian/Ubuntu it is in standard distribution) which is able to perform many operations on windows and desktops, and handles plenty of window managers. I'd suggest testing whether it works in your environment, and if so, peeking at its sources.
You may find the answer to this is dependent on the Window Manager the user is using, or even what settings they've given to the Window Manager. I like to set my Window Managers to do "focus follows mouse", which means you can't send the focus to a window that I haven't put my mouse on, unless you also warp the mouse there (is that function called XWarpMouse?).