automatically start typing in tkinter Entry - python

I'm trying to make a input screen with Tkinter that will when i type automatically receive my input without me having to click it first. would this be possible?
I wasn't able to find a tutorial or text document online to do this, and hope someone can help me with this problem! I'm on Windows 10 (bootcamped on a mac) with Python 3.8.3 64-bit.

The concept you are looking for is called "focus". When you type, the widget with the focus will receive the keypress events. So, to let you immediately type into an entry widget, force the UI to set the focus to that widget by using focus_set:
the_entry = Entry(root, ...)
the_entry.focus_set()
When the window as a whole is focused (ie: brought to the front), this will cause the keyboard focus to be set to the entry widget.

Related

Tkinter: What's the difference between grab and focus?

In tkinter I am creating a Toplevel widget to prompt the user with "Are you sure you want to exit?" every time they try to exit my application. While this is happening, I want the Toplevel widget to have full focus of my application and the user to be unable to click anything on the root window, if possible.
While trying to figure out to do this, I discovered grabs and the ability to set the focus of the application. What is the difference between these two things?
Thanks in advance.
Focus means that your window will receive all keyboard events until some other window gets the focus. A grab tells the window manager that your window should have the focus until you explicitly tell it that it is allowed to take it away (ungrab).

Automatic focus on showing deletes the placeholder text of a QLineEdit

I use PyQt4 and Python 2.7.9.
My program contains a few QLineEdit objects. The problem is that when the program is launched, one of the QLineEdits is being focused automatically, which causes my placeholder text to disappear.
Is there any way to prevent it, or at least don't let it hide the placeholder text?
Another way is
self.this_widget.clearFocus()
after window has been shown. Only in Qt5 placeholder texts are displayed even with focus. So maybe switch to PyQt5.
You can use setFocus to put the focus on a different widget (although, depending on which widget you pick, you might also need to set the focus-policy first):
self.some_other_widget.setFocusPolicy(QtCore.Qt.TabFocus)
self.some_other_widget.setFocus()
Alternatively, if you use Qt Designer to create the GUI, you could edit the tab-order so that the line-edit is not the first in the chain. This can also be done programmatically using QWidget.setTabOrder.

Grab the focus from GTK popup menu

In my python GTK project, I have a popup menu which pop-ups while typing in a particular text area. But, when type a letter popup menu get the focus and I can't type anymore in the text area until I click on the text area and grab the focus manually. I want to keep the focus to the text area as I type regularly while popup menu comes. Can anyone give tell me a way to do this. I tried widget.grab_focus() method. But it didn't solve my problem.
Also I want to know how to set the position of the popup menu. It always appears near by mouse pointer. I want it to appear near by my application.
Thanks all.
I ran into the same problem using the C API, the solution was to invoke the following functions, I presume they're approximately similar to the python equivalents:
gdk_pointer_ungrab(GDK_CURRENT_TIME);
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(menu);

highlighting a window in GNOME's window list

In order to indicate activity, some applications (e.g. Pidgin) highlight their entry in GNOME's Window List panel widget (e.g. via bold font or flashing color). This indication is reset automatically when the window is activated.
I have a terminal application for which I would like to achieve the same thing (preferably via Perl, but Python would work too) - but I have no idea where to start. I imagine I'd first have to find the terminal window (based on window title) and then trigger some kind of GTK action.
Any help would be greatly appreciated!
In a GTK application, use gtk_window_set_urgency_hint(). If you have a terminal application, you can't really do that - with libwnck you can get information about other application's windows, but as far as I know you can't get a GtkWindow pointer to another application's window.
May I suggest using the terminal beep? Of course this isn't a sure way to attract the user's attention, but some terminals are able to flash the title bar instead of beeping, or such things.
I'm not really into GTK programming, but as far as i know you want to set an "URGENT"-Flag for the Window which should be highlighted. Maybe this will get you any further. :)

Python/Tkinter: Using the new ttk.Notebook widget (custom font, trapping tab focus/mouseover)

I'm using the new ttk.Notebook widget available in Python 2.7 and Python 3.1.
I'm struggling with the following tasks:
How to change the font associated with notebook tab captions. I want to use a named font object whose size a user controls. (Could a ttk.Style help me here?)
How can I bind to tab specific keyboard focus (<FocusIn>), mouseover events (<Enter>), and rightclicks (<Button-3>). I have a total fail trying to bind to tab specific keyboard focus and mouseover events. I can bind to a <Button-3> rightclick, but I can't figure out how to determine the tab a user clicked on. Using .identify( event.x, event.y ) returns the string 'label' vs. a widget reference.
Is there a way to give tabs an id (the documentation hints at this via tab_id) so we can reference tabs independent of their physical position in an array of tabs?
Thank you,
Malcolm
We're actually answering these questions in the Tkinter mailing list; in fact, I have mixed feelings about saying anything in Stackoverflow apart from, "See the mailing list". It's surely fair to note, though, that this answers the question about fonts, and this heads a thread on tab events.

Categories

Resources