-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinter_example.py
More file actions
65 lines (55 loc) · 1.8 KB
/
Copy pathtkinter_example.py
File metadata and controls
65 lines (55 loc) · 1.8 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
import customtkinter as ctk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy as np
# ---------- CTk Settings ----------
ctk.set_appearance_mode("System")
ctk.set_default_color_theme("dark-blue")
ui = ctk.CTk()
ui.title("Live Result")
ui.geometry("670x400")
# ---------- Data ----------
x_curve = np.linspace(0, 100, 1000)
# ---------- Create Figure ----------
fig, ax = plt.subplots(figsize=(10, 4))
fig.patch.set_facecolor("#1a1a1a") # figure background
ax.set_facecolor("#1a1a1a") # axes background
ax.tick_params(colors="white") # tick labels
ax.spines['bottom'].set_color("white")
ax.spines['top'].set_color("white")
ax.spines['left'].set_color("white")
ax.spines['right'].set_color("white")
ax.yaxis.label.set_color("white")
ax.xaxis.label.set_color("white")
ax.title.set_color("white")
line, = ax.plot(x_curve, np.sin(x_curve/10) + 1, color="#00bfff")
ax.set_title("Tan Function with Phase Offset")
# ---------- Embed Graph ----------
graph = FigureCanvasTkAgg(fig, master=ui)
graph.draw()
graph.get_tk_widget().grid(row=0, column=0, columnspan=2, padx=10, pady=10)
# ---------- Slider & Label ----------
value = ctk.IntVar(value=0)
result_label = ctk.CTkLabel(
ui,
text="Phase Offset: 0",
font=("Segoe UI", 16)
)
result_label.grid(row=1, column=1, sticky="w", padx=10, pady=10)
def update_graph(phase):
phase = float(phase)
# Update phase offset
y_curve = np.sin((x_curve - phase)/10) + 1
line.set_ydata(y_curve)
graph.draw()
result_label.configure(text=f"Phase Offset: {int(phase)}")
scale = ctk.CTkSlider(
ui,
from_=0,
to=100, # adjust max phase offset if needed
command=update_graph,
width= 300
)
scale.grid(row=1, column=0, sticky="e", padx=10, pady=10)
scale.set(0)
ui.mainloop()