-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrial3.py
More file actions
97 lines (77 loc) · 2.69 KB
/
trial3.py
File metadata and controls
97 lines (77 loc) · 2.69 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import mysql.connector
import mysql
import tkinter as tki
connection = (mysql.connector.connect
(
host='localhost',
user='root',
#port=3306,
password='2025@Redmond',
database='trial_1'))
def on_button_click():
"""Function to be called when the button is clicked."""
label.config(text="Button was clicked!")
def exit_trial():
#print(f'welcome and goodbye {namae} ')
#sleep(3)
exit()
def clear_label():
label.config(text=" ")
entry_widget.delete(0, tki.END)
selected_option.set(options [0])
def save_trial ():
name_variable = entry_widget.get()
sex = selected_option.get()
#if name_variable == "":
#label.config(text=f' Enter the name please')
# else:
if connection.is_connected():
#print("Successfully connected to MySQL database.")
insert_codes = f"INSERT INTO trial_1 (Name, Gender) VALUES (%s, %s)"
label.config(text=f' Bye {name_variable} , your money is coming')
cursor = connection.cursor()
cursor.execute( insert_codes, (name_variable, sex))
connection.commit()
#sleep(2)
# Create the main application window
root = tki.Tk()
root.title("Simple DB Example")
root.configure(bg="#FFBF00")
root.geometry("400x380") # Set window size
#name_variable= tk.StringVar()
#data entry
label = tki.Label(root, text= "Enter Name", fg="white", bg="#FFBF00")
label.pack(pady=10) # Add padding for better spacing
entry_widget = tki.Entry(root, width=10,bg="white", fg="green")
entry_widget.pack(pady=10)
#data entry 2
label = tki.Label(root, text= "Enter gender", fg="white",bg="#FFBF00")
label.pack(pady=20) # Add padding for better spacing
options = ["Male", "Female", "Non-binary"]
selected_option = tki.StringVar(root)
selected_option.set(options[0]) # Set default value
dropdown = tki.OptionMenu(root, selected_option, *options)
#selection = selected_option.get()
dropdown.pack(pady=10)
# Create a label widget
label = tki.Label(root, text= "Karibu", bg="#FFBF00")
label.pack(pady=20) # Add padding for better spacing
# Create a button widget
button = tki.Button(root, text="Click Me", command=on_button_click, fg='blue')
#if on_button_click() = true
#print("welcome")
button.pack()
button2 = tki.Button(root, text="Clear", command=clear_label, fg="blue")
#if on_button_click() = true
#print("welcome")
button2.pack()
button1 = tki.Button(root, text="Exit", command=exit_trial, fg="blue", bg="#FFBF00")
#if on_button_click() = true
#print("welcome")
button1.pack()
button3 = tki.Button(root, text="Save", command=save_trial, fg="blue", bg="#FFBF00")
#if on_button_click() = true
#print("welcome")
button3.pack()
# Start the Tkinter event loop
root.mainloop()