summaryrefslogtreecommitdiff
path: root/python-graphics/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'python-graphics/main.py')
-rw-r--r--python-graphics/main.py176
1 files changed, 176 insertions, 0 deletions
diff --git a/python-graphics/main.py b/python-graphics/main.py
new file mode 100644
index 0000000..9afed98
--- /dev/null
+++ b/python-graphics/main.py
@@ -0,0 +1,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()
+