Enable keyboard enter key as a submit button in python gui

474 Views Asked by At

I just want to enable keyboard enter key to function as a submit button in Python gui for a simple windows desktop application.

import pandas as pd
from tkinter import ttk  # for treeview
import keyboard

`

1

There are 1 best solutions below

3
toyota Supra On

After typing on entry box you click submit button. As an alternative I want the Enter key to do the same as button click event

You need to add function to accept parameter. And pass the function to bind.

Try this:

import tkinter as tk
 

root = tk.Tk()
        
new_entry = tk.Entry(root)
new_entry.pack()

def enter(event=None):
    print(new_entry.get())
    
root. bind('<Return>', enter)    
 
root.mainloop()