gui.py
1.24 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
import tkinter as tk
def clear_row(button, buttons):
button_row = buttons[:3] if button in buttons[:3] else buttons[3:]
for button in button_row:
button.config(text='OFF')
def toggle_button(button):
global buttons
if button['text'] == 'ON':
button.config(text='OFF')
else:
clear_row(button, buttons)
button.config(text='ON')
def get_states():
global buttons
for i in range(3):
if buttons[i].cget('text') == 'ON':
mode = i
mode = 0
for i in range(3, 6):
if buttons[i].cget('text') == 'ON':
distortion = i - 3
distortion = 0
return mode, distortion
# Create the Tkinter window
window = tk.Tk()
window.title("Toggle Buttons")
# Create two frames for two rows
frame1 = tk.Frame(window)
frame1.pack(side=tk.TOP)
frame2 = tk.Frame(window)
frame2.pack(side=tk.TOP)
# Create six toggle buttons in two rows
buttons = []
for i in range(6):
if i < 3:
frame = frame1
else:
frame = frame2
button = tk.Button(frame, text='OFF', width=10)
button.config(command=lambda button=button: toggle_button(button))
button.pack(side=tk.LEFT)
buttons.append(button)
# Start the Tkinter event loop
window.mainloop()