-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputBox.py
60 lines (45 loc) · 1.69 KB
/
InputBox.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
53
54
55
56
57
58
59
60
import tkinter as tk
from tkinter import messagebox
def display_color(name, color):
message = f"Hello, {name}! You selected {color}."
# Display a message box with the selected color
messagebox.showinfo("Color Selection", message)
def main():
# Function to handle the button click event
def on_button_click():
selected_name = name_entry.get()
selected_color = color_var.get()
# Check if a name is entered
if not selected_name:
messagebox.showwarning("Input Error", "Please enter a name.")
return
# Check if a color is selected
if not selected_color:
messagebox.showwarning("Input Error", "Please select a color.")
return
# Display the selected color in a message box
display_color(selected_name, selected_color)
# Create the main window
root = tk.Tk()
root.title("Color Selector")
# Entry for user to input their name
name_label = tk.Label(root, text="Enter your name:")
name_label.pack()
#aidan made this comment
name_entry = tk.Entry(root)
name_entry.pack()
# Radio buttons for color selection
color_label = tk.Label(root, text="Select a color:")
color_label.pack()
color_var = tk.StringVar()
red_button = tk.Radiobutton(root, text="Red", variable=color_var, value="Red")
red_button.pack()
green_button = tk.Radiobutton(root, text="Green", variable=color_var, value="Green")
green_button.pack()
# Button to submit the form
submit_button = tk.Button(root, text="Submit", command=on_button_click)
submit_button.pack()
# Run the main loop
root.mainloop()
if __name__ == "__main__":
main()