如何使用 tkinter python3 将焦点同时设置在一个条目和一个按钮上?

How can I set the focus at an entry but at a button at the same time using tkinter python3?

我想创建一个 window 让我可以立即开始写作,但在完成后,无需按 "tab" 或任何其他键,只需按 "Enter" 即可激活一个按钮。这里有一个示例代码

from tkinter import *
from tkinter import ttk


class Aplicacion():
    def __init__(self):
        self.raiz = Tk()
        self.raiz.title("Acces")

        self.etiq1 = ttk.Label(self.raiz, text="User:").pack()

        self.ctext1 = ttk.Entry(self.raiz, width=30)
        self.ctext1.pack()
        self.ctext1.focus_set()

#Thanks to the written so far I'm able to start writing 
#in the entry box right away, just after I start the program, 
#but if I press enter the next button is not activated.

        self.boton1 = ttk.Button(self.raiz, text="Accept", command=self.raiz.destroy)

        self.boton1.pack()

        self.raiz.mainloop()

def main():
    mi_app = Aplicacion()
    return 0

if __name__ == '__main__':
    main()

How can I set the focus at an entry but at a button at the same time using tkinter python3?

你不能。根据定义,焦点只能引用单个小部件。

I want to create a window that lets me start writing right away, but just after finishing, without having to press "tab" or anything else, just to press "Enter" to activate a button.

您不需要将注意力集中在两个地方即可。您只需在输入小部件中添加一个绑定,以便在用户按下 return 键时调用按钮。

self.ctext1 = ttk.Entry(self.raiz, width=30)
self.boton1 = ttk.Button(self.raiz, text="Accept", command=self.raiz.destroy)
self.ctext1.bind("<Return>", lambda event: self.boton1.invoke())