Henny
Henny

Reputation: 1

Enable keyboard enter key as a submit button in python gui

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

`

Upvotes: 0

Views: 682

Answers (1)

toyota Supra
toyota Supra

Reputation: 4541

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()

Upvotes: 0

Related Questions