I want to run my code on raspberry pi which has a touchscreen attached to it. The GUI is made using Tkinter and I want to pop up the system onscreen keyboard when the entry is focused. Here is my current code:
For binding the entry widget with FocusIn event:
self.usernameEntry.bind('<FocusIn>', self.FocusLogin)
For calling the onscreen keyboard installed in the pi:
def FocusLogin(self,event):
os.system('florence')
My problem is that whatever I enter through florence keyboard it never automatically populates the entry widget. It is only after I close the keyboard that I actually see what I typed in. I've tried matchbox-keyboard but it just freezes the whole UI. Florence seems better but it does not update the entry field as I mentioned. I want the UI to automatically show the keys I'm pressing in the entry field.
For someone looking for the answer, I found 2 ways of solving this:
First, use subprocess.popen to create seperate threads of UI and the Keyboard. This works fine on onboard keyboard but florence lags
Second method is to run florence in background before opening the app. Then use
florence hide
florence show
to hide or display florence on the events you want to bind.
Related
I am trying to create a python 3 program with tkinter that will listen to my keyboard input even while the window is not "focused," as in I would have a separate window open, say a browser and press the tab key, which would then put the window into focus. Is there any way that I could go about doing this?
Tkinter has no support for this. Tkinter can only respond to events when it has focus.
So I was wondering if someone would be able to help shed a little light for me on something I am working on in Python.
I am creating a program with a Tkinter GUI interface that interacts with a Serial device, and an ADC chip to measure voltage. I want to make sure I properly understand how I'm building the main program loop to keep everything running smoothly. I'm going to lay out how I think the program should run, if anyone has any corrections please throw them at me.
Program is run, GUI Interface initializes
User presses a button
send signal of button through serial
measure/display voltage levels
periodically update voltage display
if button is pressed, return to step 3
Now I know to run my Tkinter GUI I set up mainloop() as the last line of code. Now my question is simply, is that all I will need? Will mainloop() continually update while it waits for another button press, or will I essentially have to creatre an update method that cycles through everything until another button is pressed?
Will mainloop() continually update while it waits for another button press, or will I essentially have to creatre an update method that cycles through everything until another button is pressed?
Not all. That's why you are using tk.Tk().mainloop(). tkinter does this for you. All you are expected to do is implement the functionality that should happen when your button is pressed. tkinter will listen for the button press.
im having some problems to send to the front a GTK window.
I have a main window (window_root) with a button that launches another window (window_programs).
with this commands:
window_root.hide()
window_programs.show()
then, in window_programs, i have a button that displays another window (window_list) with the command:
window_list.show()
window_list is modal.
The problem was that window_list appeared at the back of window_programs.
so i did some research and i found window_list.show().
The problems is that window_list appears at the front, but when i click it window_programs comes to the front!
it makes some time that i'm looking for the solution, any help will be appreciated!
You are looking for the transient-for property of the modal window (which should be available in Glade). If the modal window needs to be transient to either of the two other windows, then you need to use gtk_window_set_transient_for() as needed since the modal can only be transient for one window at a time.
A part of a small project I am working on involves 'calibrating' the coordinates of the screen of which to take a screen capture of.
By the 'screen', I refer to the entire desktop, not my GUI window.
The coordinates are calibrated when a QDialog window appears (which I've subclassed).
The user is prompted to click several locations on the screen.
I need the program to record the locations of all mouse clicks occuring anywhere on the screen - ones that don't natively trigger a QDialog mouseEvent, since they are outside this window.
Obviously overwriting the mouseEvent method does not work, since the QDialog doesn't recieve the clicks.
How can I capture global mouse clicks, so that an event is triggered and sent to the QDialog when any part of the screen is clicked?
(I'd prefer a Qt based solution, but am open to other libraries if need be).
Thanks!
There are some cross-platform examples of how to do this with http://pypi.python.org/pypi/autopy/0.51
I've assumed this isn't possible and am instead using pyHook,
letting Qt pump the messages.
I am new to both python and gui programming.
I am working on a python script which would pop-up a Tkinter dialog which needs to sit on top of another application (say Outlook for example) and should not allow me to do anything in Outlook until I click the cancel button on the tkinter dialog or until the dialog is withdrawn.
I am looking for some examples on how to do this.
It's possible, but you have to be very, very careful. If you make a programming mistake you can effectively disable your computer.
What you want to do is called a "global grab". That is, you grab all events. You do this with the tkinter command grab_set_global. You should test your application by adding a timer that automatically kills your program after a set amount of time so you aren't forced to reboot.