Parcourir la source

Изменение графика через значения в файлах

Lev_Langovskii il y a 1 mois
Parent
commit
516c7b4fea
3 fichiers modifiés avec 18 ajouts et 3 suppressions
  1. 1 0
      1234test.txt
  2. 16 3
      InterfaceL.py
  3. 1 0
      test-Interface.txt

+ 1 - 0
1234test.txt

@@ -0,0 +1 @@
+12

+ 16 - 3
InterfaceL.py

@@ -9,7 +9,9 @@ from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationTool
 from random import choice
 import matplotlib.pyplot as plt
 import matplotlib
+import matplotlib.animation as animation
 import numpy as np
+import os
 
 
 
@@ -119,7 +121,12 @@ class Interface():
         self.txt2_fw3.grid(column=0, row=2)
         self.but_fw3.grid(column=0, row=3)
 
+
+
     def create_Figure(self):
+        self.file1 = open("1234test.txt", 'r')
+        self.data = self.file1.readlines()
+        self.mnojtel = int(self.data[0])
         self.f_graf = ttk.LabelFrame(Interface.window,
                                      text='Количество импульсов в минуту', relief=SOLID)
         self.f_graf.grid(column=1, row=1, columnspan=2, rowspan=2)
@@ -128,7 +135,7 @@ class Interface():
         self.ax = self.fig.add_subplot(111)
         self.ax.set_xlabel('Время, с')
         self.ax.set_ylabel('Импульсы')
-        self.ax.plot(self.t, 5000 + 5000 * np.sin(self.t / 10), '-rh',
+        self.ax.plot(self.t, 5000 + 5000 * np.sin(self.t / self.mnojtel), '-rh',
                      linewidth=1, markersize=1, markerfacecolor='b')
         self.ax.grid(color='black', linewidth=1.0)
         self.canvas = FigureCanvasTkAgg(self.fig, master=self.f_graf)
@@ -174,7 +181,8 @@ class Interface():
         Interface.window.mainloop()
 
     def clicked_file(self):
-        self.file = filedialog.askopenfilename(filetypes=(("Text files","*.txt"),("all files","*.*")))
+        self.file1 = filedialog.askopenfile(filetypes=(("Text files","*.txt"),("all files","*.*")))
+        self.file = os.path.abspath(self.file1.name)
         self.txt.delete(0, END)
         self.txt.insert(0, self.file)
 
@@ -203,6 +211,9 @@ class Interface():
             self.Time_flag = 'normal'
             self.grafspin1.configure(state=[self.Time_flag])
         else:
+            self.file1 = open(self.file, 'r')
+            self.data = self.file1.readlines()
+            self.mnojtel = int(self.data[0])
             self.Time_flag = 'disabled'
             self.grafspin1.configure(state=[self.Time_flag])
             self.fig.clear()
@@ -210,8 +221,10 @@ class Interface():
             self.ax = self.fig.add_subplot(111)
             self.t = np.linspace(0, int(self.spinbox_varTime.get()), num=10000)
             self.ax.set_ylim(bottom=0, top=10000)
+            self.ax.set_xlabel('Время, с')
+            self.ax.set_ylabel('Импульсы')
             self.ax.plot(self.t,
-            int(self.spinbox_var1.get()) + abs(int(self.spinbox_var1.get()) - int(self.spinbox_var2.get())) * 0.5 * (1 + np.sin(self.t / 10)),
+            int(self.spinbox_var1.get()) + abs(int(self.spinbox_var1.get()) - int(self.spinbox_var2.get())) * 0.5 * (1 + np.sin(self.t / self.mnojtel)),
                          '-rh', linewidth=1, markersize=1, markerfacecolor='b')
             self.ax.grid(color='black', linewidth=1.0)
             self.canvas = FigureCanvasTkAgg(self.fig, master=self.f_graf)

+ 1 - 0
test-Interface.txt

@@ -0,0 +1 @@
+15