-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
46 lines (36 loc) · 1.17 KB
/
example.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
import tkinter as tk
from tkinter import messagebox
# Function to display text on label
def display_text():
text = input_text.get()
if text:
label_text.config(text="You entered: " + text)
else:
messagebox.showerror("Error", "Please enter some text.")
# Function to clear the input field
def clear_input():
input_text.delete(0, tk.END)
label_text.config(text="")
# Initialize the root window
root = tk.Tk()
root.title("Tkinter Example Application")
# Create a label for input instruction
label_input = tk.Label(root, text="Enter text:")
label_input.pack()
# Create an entry for text input
input_text = tk.Entry(root)
input_text.pack()
# Create a frame for buttons
button_frame = tk.Frame(root)
button_frame.pack()
# Create a button to display text
button_display = tk.Button(button_frame, text="Display", command=display_text)
button_display.pack(side=tk.LEFT, padx=5)
# Create a button to clear input
button_clear = tk.Button(button_frame, text="Clear", command=clear_input)
button_clear.pack(side=tk.LEFT, padx=5)
# Create a label to display the input text
label_text = tk.Label(root, text="")
label_text.pack()
# Run the main loop
root.mainloop()