123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- from idlelib.colorizer import color_config
- from tkinter import *
- import tkinter as tk
- from tkinter import ttk
- from tkinter import filedialog
- from tkinter.ttk import Combobox
- from matplotlib.figure import Figure
- from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
- from random import choice
- import matplotlib.pyplot as plt
- import matplotlib
- import numpy as np
- class Interface():
- window = Tk()
- def __init__(self):
- pass
- def create_widgets_S(self):
- Interface.window.title("project_gamma_new_2vi")
- Interface.window.geometry('500x250+100+100')
- photo = tk.PhotoImage(file='iconka.png')
- Interface.window.iconphoto(False, photo)
- self.f_top = ttk.LabelFrame(Interface.window, text="Виртуальный COM порт", relief=SOLID, padding=[8, 10])
- self.combo = Combobox(self.f_top)
- self.combo['values'] = (1, 2, 3, 4, 5)
- self.combo.current(4)
- self.f_top.grid(column=0, row=0)
- self.combo.pack(side=BOTTOM)
- self.f_file = ttk.LabelFrame(Interface.window, text="Выбрать файл txt для записи", relief=SOLID, padding=[8, 10])
- self.f_file.grid(column=1, row=0)
- self.txt = Entry(self.f_file, width=40)
- self.txt.pack(side=LEFT)
- self.btn = Button(self.f_file, height=1, text='Файл', bg="gray", fg="red", command=self.clicked_file)
- self.btn.pack(side=LEFT)
- self.f_start = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
- self.t1 = Label(self.f_start, text="Состояние работы", fg="black")
- self.t2 = Label(self.f_start, text="Начать сбор данных", fg="black")
- self.t3 = Label(self.f_start, text="Остановить сбор данных", fg="black")
- self.t4 = Label(self.f_start, text="Выключено", fg="white", bg="black")
- self.button_start = Button(self.f_start, text="Пуск", bg="lightgray", fg="black", command=self.clicked_start1)
- self.button_startoff = Button(self.f_start, text="Стоп", bg="lightgray", fg="red",
- command=self.clicked_start2,
- state=['disabled'])
- self.f_start1= ttk.LabelFrame(Interface.window, text='Принятые символы', relief=SOLID, padding=[8, 10])
- self.t_entry = Entry(self.f_start1, width=40)
- self.f_start.grid(column=2, row=0)
- self.f_start1.grid(column=3, row=0)
- self.t1.grid(column=0, row=0)
- self.t2.grid(column=1, row=0)
- self.t3.grid(column=2, row=0)
- self.t4.grid(column=0, row=1)
- self.t_entry.grid(column=0, row=1)
- self.button_start.grid(column=1, row=1)
- self.button_startoff.grid(column=2, row=1)
- def create_widgets_W(self):
- self.f_W = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
- self.f_W.grid(column=0, row=1)
- self.tspin1 = Label(self.f_W, text="Время экспозиции, с", fg="black")
- self.tspin2 = Label(self.f_W, text="Макс. время сбора данных, с", fg="black")
- self.tspin3 = Label(self.f_W, text="Прошло времени, с", fg="black")
- self.spin1 = Spinbox(self.f_W, from_=0, to=100, width=7)
- self.spin2 = Spinbox(self.f_W, from_=0, to=10000000, increment=500, width=11)
- self.t_entry = Entry(self.f_W, width=20, state=['disabled'])
- self.tspin1.grid(column=0, row=0, ipadx=10)
- self.spin1.grid(column=0, row=1, pady=10)
- self.tspin2.grid(column=0, row=2, ipadx=10)
- self.spin2.grid(column=0, row=3, pady=10)
- self.tspin3.grid(column=0, row=4, pady=10)
- self.t_entry.grid(column=0, row=5)
- self.f_W1 = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
- self.f_W1.grid(column=0, row=2)
- self.tspin_0 = Label(self.f_W1, text="Коэффициент делителя", fg="black")
- self.spin_0 = Spinbox(self.f_W1, from_=0, to=100, width=7)
- self.tspin_0.grid(column=0, row=0, ipadx=10)
- self.spin_0.grid(column=0, row=1, pady=10)
- self.f_W2 = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
- self.f_W2.grid(column=0, row=3)
- self.spin1_zap = Spinbox(self.f_W2, from_=0.0, to=50.0, increment=0.1, width=6)
- self.spin2_zap = Spinbox(self.f_W2, from_=0, to=100, increment=1, width=6)
- self.spin3_zap = Spinbox(self.f_W2, from_=0, to=500, width=6)
- self.spin4_zap = Spinbox(self.f_W2, from_=0, to=500 , width=6)
- self.tspin1_zap = Label(self.f_W2, text="ЦАП канал 1.0...3.29В", fg="black")
- self.tspin2_zap = Label(self.f_W2, text="ЦАП канал 2.0...3.29В", fg="black")
- self.tspin3_zap = Label(self.f_W2, text="ЦАП канал 3.1...256", fg="black")
- self.tspin4_zap = Label(self.f_W2, text="ЦАП канал 4.1...256", fg="black")
- self.tbut1_zap = Label(self.f_W2, text='''Обновить значение
- каналов DAC''', fg="black")
- self.tbut2_zap = Label(self.f_W2, text='''Прочесть текущее
- значение каналов DAC''', fg="black")
- self.button1_zap= Button(self.f_W2, text="Обновить", bg="lightgray", fg="black")
- self.button2_zap = Button(self.f_W2, text="Прочесть", bg="lightgray", fg="black")
- self.tspin1_zap.grid(column=0, row=0, ipadx=10)
- self.spin1_zap.grid(column=0, row=1, pady=10)
- self.tspin2_zap.grid(column=0, row=2, ipadx=10)
- self.spin2_zap.grid(column=0, row=3, pady=10)
- self.tspin3_zap.grid(column=0, row=4, ipadx=10)
- self.spin3_zap.grid(column=0, row=5, pady=10)
- self.tspin4_zap.grid(column=0, row=6, ipadx=10)
- self.spin4_zap.grid(column=0, row=7, pady=10)
- self.tbut1_zap.grid(column=0, row=8)
- self.button1_zap.grid(column=0, row=9)
- self.tbut2_zap.grid(column=0, row=10)
- self.button2_zap.grid(column=0, row=11)
- self.f_W3 = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
- self.txt0_fw3 = Label(self.f_W3, text="Порт В1 напряжения", fg="black")
- self.txt1_fw3 = Label(self.f_W3, text=" 0 B ", fg="black", bg="pink")
- self.m = ' 0 B '
- self.txt2_fw3 = Label(self.f_W3, text='''Выбор напряжения:
- 0 В 3.3B''')
- self.but_fw3 = Button(self.f_W3, text='<---', command=self.clicked_V)
- self.f_W3.grid(column=0, row=4)
- self.txt0_fw3.grid(column=0, row=0)
- self.txt1_fw3.grid(column=0, row=1, pady=10)
- self.txt2_fw3.grid(column=0, row=2)
- self.but_fw3.grid(column=0, row=3)
- def create_Figure(self):
- self.f_graf = ttk.LabelFrame(Interface.window,
- text='Количество импульсов в минуту', relief=SOLID)
- self.f_graf.grid(column=1, row=1, columnspan=2, rowspan=2)
- self.fig = Figure(figsize=(7, 4), dpi=80)
- self.t = np.linspace(0, 2 * np.pi, num=100)
- self.ax = self.fig.add_subplot(111)
- self.ax.set_xlabel('Время, с')
- self.ax.set_ylabel('Импульсы')
- self.ax.plot(self.t, np.sin(self.t), '-rh', linewidth=3, markersize=1, markerfacecolor='b',
- label=r'$\ y=sin(x) $')
- self.ax.grid(color='black', linewidth=1.0)
- self.ax.legend(fontsize=12)
- self.canvas = FigureCanvasTkAgg(self.fig, master=self.f_graf)
- self.canvas.draw()
- self.canvas.get_tk_widget().grid(column=0, row=0)
- Interface.window.after(100, None)
- self.f_grafbtn = ttk.LabelFrame(self.f_graf, text='Время отоброжения', padding=[8, 10])
- self.f_grafbtn.grid(column=1, row=0)
- self.tgrafsp = Label(self.f_grafbtn, text="Начало время, с", fg="black")
- self.tgrafsp.grid(column=0, row=0)
- self.grafspin = Spinbox(self.f_grafbtn, from_=0, to=100, width=7)
- self.grafspin.grid(column=0, row=1)
- self.t1grafbtn = Label(self.f_grafbtn, text="Времени конца времени", fg="black")
- self.t1grafbtn.grid(column=0, row=2)
- def start(self):
- self.mennuB()
- self.create_widgets_S()
- self.create_widgets_W()
- self.create_Figure()
- Interface.window.mainloop()
- def clicked_file(self):
- self.file = filedialog.askopenfilename(filetypes=(("Text files","*.txt"),("all files","*.*")))
- self.txt.delete(0, END)
- self.txt.insert(0, self.file)
- def clicked_start1(self):
- self.button_start.configure(state=["disabled"])
- self.t4.configure(text="Включено", bg="black", fg="green")
- self.button_startoff.configure(state=["active"])
- def clicked_start2(self):
- self.button_start.configure(state=["active"])
- self.t4.configure(text="Выключено", bg="black", fg="white")
- self.button_startoff.configure(state=['disabled'])
- def clicked_V(self):
- if self.m == " 0 B ":
- self.m = ' 3.3 B '
- self.txt1_fw3.configure(text=' 3.3 B ')
- self.but_fw3.configure(text="--->")
- else:
- self.m = ' 0 B '
- self.but_fw3.configure(text='<---')
- self.txt1_fw3.configure(text=' 0 B ')
- def mennuB(self):
- menubar1 = tk.Menu(self.window)
- self.window.config(menu=menubar1)
- setting_menu1 = tk.Menu(menubar1)
- setting_menu1.add_command(label='---')
- menubar1.add_cascade(label='File', menu=setting_menu1)
- setting_menu2 = tk.Menu(menubar1)
- setting_menu2.add_command(label='----')
- menubar1.add_cascade(label='Edit', menu=setting_menu2)
- setting_menu3 = tk.Menu(menubar1)
- setting_menu3.add_command(label='---')
- menubar1.add_cascade(label='Operate', menu=setting_menu3)
- setting_menu4 = tk.Menu(menubar1)
- setting_menu4.add_command(label='-----')
- menubar1.add_cascade(label='Tools', menu=setting_menu4)
- setting_menu5 = tk.Menu(menubar1)
- setting_menu5.add_command(label='-----')
- menubar1.add_cascade(label='Window', menu=setting_menu5)
- setting_menu6 = tk.Menu(menubar1)
- setting_menu6.add_command(label='-----')
- menubar1.add_cascade(label='Help', menu=setting_menu6)
- interface = Interface()
- interface.start()
|