-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtk2.py
52 lines (41 loc) · 1.41 KB
/
tk2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Working with Entry widget & creating a form
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showinfo
# root window
root = tk.Tk()
root.geometry("450x250")
root.resizable(False, False)
root.title('Sign In')
# create two string variables to hold the current text of the email
# and password Entry widgets: store email address and password
email = tk.StringVar()
password = tk.StringVar()
def login_clicked():
""" callback when the login button clicked
"""
msg = f'You entered email: {email.get()} and password: {password.get()}'
showinfo(
title='Information',
message=msg
)
# sign in frame
signin = ttk.Frame(root)
signin.pack(padx=10, pady=10, fill='x', expand=True)
# email
email_label = ttk.Label(signin, text="Email Address:")
email_label.pack(fill='x', expand=True)
email_entry = ttk.Entry(signin, textvariable=email)
email_entry.pack(fill='x', expand=True)
# sets focus on the email entry:
email_entry.focus()
# password
password_label = ttk.Label(signin, text="Password:")
password_label.pack(fill='x', expand=True)
# create the password entry widget, assign the password variable to its textvariable
password_entry = ttk.Entry(signin, textvariable=password, show="*")
password_entry.pack(fill='x', expand=True)
# login button
login_button = ttk.Button(signin, text="Login", command=login_clicked)
login_button.pack(fill='x', expand=True, pady=10)
root.mainloop()