- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.py
More file actions
Latest commit
188 lines (163 loc) · 6.14 KB
/
Copy pathGUI.py
File metadata and controls
188 lines (163 loc) · 6.14 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Judul : Program Remote AC dengan GUI
# Keterangan : Program ini mensimulasikan remote AC melalui GUI
importtkinterastk
fromtkinterimportttk, messagebox
fromPILimportImage, ImageTk
importthreading
importtime
# Global Variables
power_status="Off"
swing_status="Off"
fan_status="Low"
mode_status="Normal"
timer_status="Off"
temperature_status=23
# Functions and Procedures
defpower():
globalpower_status
ifpower_status=="Off":
power_status="On"
else:
power_status="Off"
reset()
update_display()
defpower_check():
returnpower_status=="On"
defswing():
globalswing_status
ifpower_check():
swing_status="On"ifswing_status=="Off"else"Off"
update_display()
else:
messagebox.showwarning("Warning", "Your power is off, cannot continue command.")
deffan():
globalfan_status
ifpower_check():
iffan_status=="Low":
fan_status="Medium"
eliffan_status=="Medium":
fan_status="High"
else:
fan_status="Low"
update_display()
else:
messagebox.showwarning("Warning", "Your power is off, cannot continue command.")
defmode():
globalmode_status
ifpower_check():
modes= ["Normal", "Cool", "Dry", "Fan", "Turbo", "Quiet", "Sleep", "Auto"]
current_index=modes.index(mode_status)
mode_status=modes[(current_index+1) %len(modes)]
update_display()
else:
messagebox.showwarning("Warning", "Your power is off, cannot continue command.")
deftimer_thread(duration_minutes):
globalpower_status, timer_status
time.sleep(duration_minutes*60)
reset()
update_display()
defreset():
globalpower_status, swing_status, fan_status, mode_status, timer_status, temperature_status
power_status="Off"
swing_status="Off"
fan_status="Low"
mode_status="Normal"
timer_status="Off"
temperature_status=23
deftimer():
globaltimer_status
ifpower_check():
try:
duration_minutes=int(timer_entry.get())
timer_entry.delete(0, tk.END)
timer_status=f"{duration_minutes} min"
threading.Thread(target=timer_thread, args=(duration_minutes,), daemon=True).start()
update_display()
exceptValueError:
messagebox.showwarning("Warning", "Please enter a valid number for the timer.")
else:
messagebox.showwarning("Warning", "Your power is off, cannot continue command.")
deftemperature_up():
globaltemperature_status
ifpower_check():
iftemperature_status<32:
temperature_status+=1
update_display()
else:
messagebox.showwarning("Warning", "Your power is off, cannot continue command.")
deftemperature_down():
globaltemperature_status
ifpower_check():
iftemperature_status>16:
temperature_status-=1
update_display()
else:
messagebox.showwarning("Warning", "Your power is off, cannot continue command.")
defupdate_display():
ifpower_status=="Off":
display_label.config(image=power_image, text="")
control_frame.pack_forget()
else:
display_label.config(image="", text=f"Power: {power_status}\n"
f"Temperature: {temperature_status} °C\n"
f"Swing: {swing_status}\n"
f"Fan: {fan_status}\n"
f"Mode: {mode_status}\n"
f"Timer: {timer_status}",
font=("Helvetica", 14), justify="center", foreground="#FFFFFF", background="#4A4A4A")
control_frame.pack(pady=20)
# GUI Setup
root=tk.Tk()
root.title("Remote AC")
root.configure(bg="#1F1F1F")
# Center Window
window_width, window_height=400, 600
screen_width, screen_height=root.winfo_screenwidth(), root.winfo_screenheight()
offset_x, offset_y= (screen_width-window_width) //2, (screen_height-window_height) //2-50
root.geometry(f"{window_width}x{window_height}+{offset_x}+{offset_y}")
# Style
style=ttk.Style()
style.theme_use("clam")
style.configure("TButton", font=("Helvetica", 12), padding=5, relief="flat")
style.configure("TLabel", font=("Helvetica", 12), background="#1F1F1F", foreground="#FFFFFF")
# Power Image
power_image_file="Power.png"
try:
power_image=ImageTk.PhotoImage(Image.open(power_image_file).resize((150, 150)))
exceptFileNotFoundError:
power_image=None
# Display
display_label=ttk.Label(root, background="#4A4A4A", anchor="center", width=50)
display_label.pack(pady=20)
# Controls
control_frame=ttk.Frame(root, style="TFrame")
control_frame.pack(pady=10)
# Power Button
power_button=ttk.Button(root, text="Power", command=power, style="TButton")
power_button.pack(pady=10)
# Temperature Controls
temp_frame=ttk.Frame(control_frame)
temp_frame.pack(pady=10)
temp_up_button=ttk.Button(temp_frame, text="Temperature (↑)", command=temperature_up)
temp_up_button.pack(side="left", padx=10)
temp_down_button=ttk.Button(temp_frame, text="Temperature (↓)", command=temperature_down)
temp_down_button.pack(side="left", padx=10)
# Swing Button
swing_button=ttk.Button(control_frame, text="Swing", command=swing)
swing_button.pack(pady=10)
# Mode & Fan Controls
mode_fan_frame=ttk.Frame(control_frame)
mode_fan_frame.pack(pady=10)
fan_button=ttk.Button(mode_fan_frame, text="Fan Speed", command=fan)
fan_button.pack(side="left", padx=10)
mode_button=ttk.Button(mode_fan_frame, text="Change Mode", command=mode)
mode_button.pack(side="left", padx=10)
# Timer Controls
timer_label=ttk.Label(control_frame, text="Set Timer (minutes):")
timer_label.pack(pady=5)
timer_entry=ttk.Entry(control_frame, width=10)
timer_entry.pack(pady=5)
timer_button=ttk.Button(control_frame, text="Set Timer", command=timer)
timer_button.pack(pady=10)
update_display()
root.mainloop()