Home > Enterprise >  How to take input in Tkinter and then pass it into a function to get the Output
How to take input in Tkinter and then pass it into a function to get the Output

Time:12-02

What I want is, that take input from the User through Tkinter. I pass the inputs as an argument to my function and then the function performs itself.

Here is my Code-

import tkinter as tk
from tkinter import *
root=tk.Tk()
root.geometry("644x344")
def getvals(email,date_to,date_from):
    """
    function executes itself 
    """    
Label(root,text="Automatic Email Saver",font="comicansms 13 bold",pady=15).grid(row=0,column=3)
Email = Label(root, text="Email")
date_start = Label(root, text="Starting Date And Time")
date_end = Label(root, text="Ending Date and Time")
Email.grid(row=1, column=2)
date_start.grid(row=2, column=2)
date_end.grid(row=3, column=2)
Emailvalue = StringVar()
date_startvalue = StringVar()
date_endvalue = StringVar()
Emailentry = Entry(root, textvariable=Emailvalue)
date_toentry = Entry(root, textvariable=date_startvalue)
date_endentry = Entry(root, textvariable=date_endvalue)
Emailentry.grid(row=1, column=3)
date_toentry.grid(row=2, column=3)
date_endentry.grid(row=3, column=3)
Button(text="Submit", command=getvals).grid(row=5, column=3)
root.mainloop()

 

CodePudding user response:

You need not use any arguments for your function.

Just simply .get() the values.

email = Emailentry.get()
date_to = date_toentry.get()
date_from = date_endentry.get()
  • Related