HOME/Articles/

tkinter example processEnterKey (snippet)

Article Outline

Python tkinter (gui) example 'processEnterKey'

Functions in program:

  • def evaluate(event):

processEnterKey

Python tkinter example: processEnterKey

from tkinter import *
from math import *

def evaluate(event):
    res.configure(text = "Result: " + str(eval(entry.get())))

w = Tk()
Label(w, text="Your Expression:").pack()
entry = Entry(w)
entry.bind("<Return>", evaluate)
entry.pack()
res = Label(w)
res.pack()
w.mainloop()