Concept

Getting user data from the user input

We can get user input from the text entry field using the .get() method.

email = entry_email.get()

We can use combine functions and user input to use the data in a more useful way.

Following example is a simple login system to get email and password from user.

import tkinter as tk window = tk.Tk() window.title("1Cademy") window.geometry("350x100") admin_email = "admin@gmail.com" admin_password = "admin123" #gets user input and checks for correct/incorrect info def getInfo(): email = entry_email.get() password = entry_password.get() if (email == admin_email and password == admin_password): print("ACCESS GRANTED") else: print("ACCESS DENIED") label = tk.Label(text="Email:") label.pack() entry_email = tk.Entry() entry_email.pack() label = tk.Label(text="Password:") label.pack() entry_password = tk.Entry() entry_password.pack() #when button1 is clicked, it calls getInfo function button1 = tk.Button(text="Login", foreground="red", command=getInfo) button1.pack() window.mainloop()
Image 0

0

1

Updated 2021-05-11

Contributors are:

Who are from:

References


Tags

Python Programming Language

Data Science