-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTkinter.py
More file actions
31 lines (23 loc) · 874 Bytes
/
Tkinter.py
File metadata and controls
31 lines (23 loc) · 874 Bytes
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
import tkinter as tk
from functools import partial
def printDetails(usernameEntry):
usernameText = usernameEntry.get()
print("User entered:", usernameText)
# Create the main Tkinter window
tkWindow = tk.Tk()
tkWindow.geometry('400x150')
tkWindow.title('Python Examples')
# Label for user input
usernameLabel = tk.Label(tkWindow, text="Enter your name")
# Entry widget for user input
usernameEntry = tk.Entry(tkWindow)
# Define a callable function with printDetails function and usernameEntry argument
printDetailsCallable = partial(printDetails, usernameEntry)
# Submit button
submitButton = tk.Button(tkWindow, text="Submit", command=printDetailsCallable)
# Place label, entry, and button in a grid
usernameLabel.grid(row=0, column=0)
usernameEntry.grid(row=0, column=1)
submitButton.grid(row=1, column=1)
# Start the Tkinter event loop
tkWindow.mainloop()