I use tkinter to open an entry box to add some tags to certain text I collect. Basically, when I copy the text, tkinter opens the entry box so I can insert my tags. The relevant part of the code is as follows (someone in this forum helped me out with it):
import tkinter
master = tkinter.Tk()
entry = tkinter.Entry(master)
entry.pack()
def close(event):
if keyboard.is_pressed('enter'):
string=entry.get()
master.destroy()
master.bind('<Key>', close)
master.mainloop()
As the purpose of the code is to save AS MUCH time as possible, I would like that when the entry box pops up I don't have to manually go to the box with the mouse and click on it to start writting. I haven't found the way to do that. Is it possible?
Simply apply focus()
to entry()
after you pack it.
You can also remove the need to check for Enter
with the keyboard
library by simply binding to Return
instead of Key
.
import tkinter as tk
master = tk.Tk()
entry = yk.Entry(master)
entry.pack()
entry.focus()
def close(event):
string = entry.get()
master.destroy()
master.bind('<Return>', close)
master.mainloop()
Side note:
focus()
and focus_set()
are the exact same command. So either works. focus()
is just an alias for focus_set()