You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.6 KiB
86 lines
2.6 KiB
# -*- encoding: utf-8 -*-
|
|
"""
|
|
@Author: packy945
|
|
@FileName: input.py
|
|
@DateTime: 2023/7/19 16:59
|
|
@SoftWare: PyCharm
|
|
"""
|
|
import tkinter as tk
|
|
from tkinter import *
|
|
import numpy as np
|
|
|
|
import data as gl_data
|
|
from fitting import selfdata_show
|
|
|
|
global top
|
|
def input_num(root_tk):
|
|
global top
|
|
top = tk.Toplevel(root_tk)
|
|
label1 = Label(top, text="坐标点个数")
|
|
label1.grid(row=0) # 这里的side可以赋值为LEFT RTGHT TOP BOTTOM
|
|
num1 = IntVar()
|
|
entry1 = Entry(top, textvariable=num1)
|
|
num1.set(0)
|
|
entry1.grid(row=0, column=1)
|
|
Label(top, text=" ").grid(row=0, column=3)
|
|
Button(top, text="确定", command=lambda: input_data(root_tk, int(entry1.get()))).grid(row=0, column=3)
|
|
top.mainloop()
|
|
def input_data(root_tk, num):
|
|
global top
|
|
sample_x = []
|
|
sample_y = []
|
|
sample_data = []
|
|
top.destroy()
|
|
top = tk.Toplevel(root_tk)
|
|
|
|
def add_sample_data():
|
|
try:
|
|
x = float(entry_x.get())
|
|
y = float(entry_y.get())
|
|
except:
|
|
label_status.config(text="输入不合法")
|
|
return
|
|
entry_x.delete(0, tk.END)
|
|
entry_y.delete(0, tk.END)
|
|
if min(x, y) < gl_data.LOW or max(x, y) > gl_data.HIGH:
|
|
label_status.config(text="输入超过范围")
|
|
return
|
|
elif len(sample_data) < num:
|
|
label_status.config(text="点对已添加")
|
|
sample_data.append((x, y))
|
|
sample_x.append(x)
|
|
sample_y.append(y)
|
|
else:
|
|
label_status.config(text="已达到最大数量")
|
|
def check_sample_data():
|
|
if len(sample_data) == num:
|
|
label_status.config(text="已达到最大数量")
|
|
gl_data.X = np.array(sample_x)
|
|
gl_data.Y = np.array(sample_y)
|
|
print('已添加', sample_data)
|
|
top.destroy()
|
|
selfdata_show(gl_data.X, gl_data.Y, gl_data.LOW, gl_data.HIGH)
|
|
else:
|
|
label_status.config(text="还需输入{}个点对".format(num - len(sample_data)))
|
|
print(sample_data)
|
|
|
|
label_x = tk.Label(top, text="X 值:")
|
|
label_x.pack()
|
|
entry_x = tk.Entry(top)
|
|
entry_x.pack()
|
|
label_y = tk.Label(top, text="Y 值:")
|
|
label_y.pack()
|
|
entry_y = tk.Entry(top)
|
|
entry_y.pack()
|
|
button_add = tk.Button(top, text="添加", command=add_sample_data)
|
|
button_add.pack()
|
|
button_check = tk.Button(top, text="检查", command=check_sample_data)
|
|
button_check.pack()
|
|
label_status = tk.Label(top, text="")
|
|
label_status.pack()
|
|
top.mainloop()
|
|
|
|
if __name__ == '__main__':
|
|
root = tk.Tk()
|
|
input_num(root)
|