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
|
import tkinter as tk
from tkinter import filedialog as fd
class PlotType:
USER = 1
PRESET = 2
POINT = 3
class PresetPlot:
LINE = 0
PARABOLA = 1
OPTIONS = ["ax + b = 0", "ax^2 + bx + c = 0"]
class PlotTypeFrame(tk.Frame):
def __init__(self, master, plot_type_var, callback):
super().__init__(master)
self.master = master
self.plot_type = plot_type_var
self.callback = callback
self.create_widgets()
self.set_style()
def set_style(self):
self.font = (None, "15")
# self.font["size"] = 17
self.bg = "#ffffff"
self["bg"] = self.bg
self.preset_plot["bg"] = self.bg
self.preset_plot["font"] = self.font
self.preset_plot["bd"] = 0
self.user_plot["bg"] = self.bg
self.user_plot["font"] = self.font
self.user_plot["bd"] = 0
self.point_plot["bg"] = self.bg
self.point_plot["font"] = self.font
self.point_plot["bd"] = 0
def create_widgets(self):
self.preset_plot = tk.Radiobutton(self)
self.preset_plot["variable"] = self.plot_type
self.preset_plot["text"] = "Предустановленный"
self.preset_plot["value"] = PlotType.PRESET
self.preset_plot["command"] = self.callback
self.preset_plot.grid(row=0, column=0)
self.user_plot = tk.Radiobutton(self)
self.user_plot["variable"] = self.plot_type
self.user_plot["text"] = "Пользовательский"
self.user_plot["value"] = PlotType.USER
self.user_plot["command"] = self.callback
self.user_plot.grid(row=1, column=0)
self.point_plot = tk.Radiobutton(self)
self.point_plot["variable"] = self.plot_type
self.point_plot["text"] = "По точкам"
self.point_plot["value"] = PlotType.POINT
self.point_plot["command"] = self.callback
self.point_plot.grid(row=2, column=0)
self.preset_plot.select()
class PresetPlotFrame(tk.Frame):
def __init__(self, master, preset_type):
super().__init__(master)
self.master = master
self.preset_type = preset_type
self.create_widgets()
def create_widgets(self):
self.label = tk.Label(self)
self.label["text"] = "Предустановленный"
self.label.grid(row=0, column=0)
self.options = tk.OptionMenu(
self,
self.preset_type,
*PresetPlot.OPTIONS
)
self.options.grid(row=1, column=0)
class UserPlotFrame(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.master = master
self.create_widgets()
def create_widgets(self):
self.label = tk.Label(self)
self.label["text"] = "Пользовательский"
self.label.grid(row=0, column=0)
class PointPlotFrame(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.master = master
self.create_widgets()
def create_widgets(self):
self.label = tk.Label(self)
self.label["text"] = "Поточечный"
self.label.grid(row=0, column=0)
self.choose_file = tk.Button(self)
self.choose_file["text"] = "Выбрать файл"
self.choose_file["command"] = self.open_file
self.choose_file.grid(row=1, column=0)
self.filepath = tk.Label(self)
self.filepath.grid(row=1, column=1)
def open_file(self):
a = tk.filedialog.askopenfile()
self.filepath["text"] = a.name
print(a)
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("400x250")
self.create_widgets()
def create_widgets(self):
self.plot_type = tk.IntVar()
self.preset_type = tk.IntVar()
# Фрейм с выбором типа графика
self.plot_type_frame = PlotTypeFrame(
self,
self.plot_type,
self.change_plot_type
)
self.plot_type_frame.pack(side=tk.LEFT)
# Создаём фреймы с настройкой выбранного типа графика
self.preset_plot_frame = PresetPlotFrame(self, self.preset_type)
self.user_plot_frame = UserPlotFrame(self)
self.point_plot_frame = PointPlotFrame(self)
self.preset_plot_frame.pack(side=tk.RIGHT)
def change_plot_type(self):
if self.plot_type.get() == PlotType.PRESET:
self.preset_plot_frame.pack(side=tk.RIGHT)
self.user_plot_frame.pack_forget()
self.point_plot_frame.pack_forget()
elif self.plot_type.get() == PlotType.USER:
self.preset_plot_frame.pack_forget()
self.user_plot_frame.pack(side=tk.RIGHT)
self.point_plot_frame.pack_forget()
elif self.plot_type.get() == PlotType.POINT:
self.preset_plot_frame.pack_forget()
self.user_plot_frame.pack_forget()
self.point_plot_frame.pack(side=tk.RIGHT)
if __name__ == "__main__":
app = App()
app.mainloop()
|