|
|
@ -1,7 +1,7 @@
|
|
|
|
import math
|
|
|
|
import math
|
|
|
|
from collections import OrderedDict
|
|
|
|
from collections import OrderedDict
|
|
|
|
from time import sleep
|
|
|
|
from time import sleep
|
|
|
|
from tkinter import *
|
|
|
|
from ttkbootstrap import *
|
|
|
|
import tkinter.font as tkFont
|
|
|
|
import tkinter.font as tkFont
|
|
|
|
from tkinter import messagebox
|
|
|
|
from tkinter import messagebox
|
|
|
|
from tkinter.ttk import Treeview
|
|
|
|
from tkinter.ttk import Treeview
|
|
|
@ -46,8 +46,8 @@ class Graph(Canvas):
|
|
|
|
绘制坐标轴
|
|
|
|
绘制坐标轴
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
self.delete("all")
|
|
|
|
self.delete("all")
|
|
|
|
self.create_line(0, self.origin[1], self.width, self.origin[1], fill='white', arrow=LAST) # 一象限xy轴
|
|
|
|
self.create_line(0, self.origin[1], self.width, self.origin[1], fill='black', arrow=LAST) # 一象限xy轴
|
|
|
|
self.create_line(self.origin[0], 0, self.origin[0], self.height, fill='white', arrow=FIRST)
|
|
|
|
self.create_line(self.origin[0], 0, self.origin[0], self.height, fill='black', arrow=FIRST)
|
|
|
|
|
|
|
|
|
|
|
|
def draw_scale(self):
|
|
|
|
def draw_scale(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -77,6 +77,9 @@ class Graph(Canvas):
|
|
|
|
self.draw_axis()
|
|
|
|
self.draw_axis()
|
|
|
|
self.draw_scale()
|
|
|
|
self.draw_scale()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_xy(self):
|
|
|
|
|
|
|
|
return -math.ceil((self.origin[0] / self.bili_x)) + 1, math.ceil((self.width - self.origin[0]) / self.bili_x)
|
|
|
|
|
|
|
|
|
|
|
|
def draw_graph(self, func, draw_precision=0.1, count=1000, bili_x=20, bili_y=40, c='blue'):
|
|
|
|
def draw_graph(self, func, draw_precision=0.1, count=1000, bili_x=20, bili_y=40, c='blue'):
|
|
|
|
'xmin,xmax 自变量的取值范围; c 图像颜色'
|
|
|
|
'xmin,xmax 自变量的取值范围; c 图像颜色'
|
|
|
|
'x0,y0 原点坐标 w,h 横纵轴半长 draw_precision 步进'
|
|
|
|
'x0,y0 原点坐标 w,h 横纵轴半长 draw_precision 步进'
|
|
|
@ -84,7 +87,7 @@ class Graph(Canvas):
|
|
|
|
self.draw_axis()
|
|
|
|
self.draw_axis()
|
|
|
|
self.draw_scale()
|
|
|
|
self.draw_scale()
|
|
|
|
w1, w2 = self.bili_x, self.bili_y # w1,w2为自变量和函数值在横纵轴上的放大倍数
|
|
|
|
w1, w2 = self.bili_x, self.bili_y # w1,w2为自变量和函数值在横纵轴上的放大倍数
|
|
|
|
xmin, xmax = -math.ceil((self.origin[0] / self.bili_x)) + 1, math.ceil((self.width - self.origin[0]) / self.bili_x)
|
|
|
|
xmin, xmax = self.get_xy()
|
|
|
|
co2 = []
|
|
|
|
co2 = []
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
for x in arange(xmin, xmax, draw_precision): # draw_precision----画图精度
|
|
|
|
for x in arange(xmin, xmax, draw_precision): # draw_precision----画图精度
|
|
|
@ -271,32 +274,32 @@ class FunctionDisplay(Frame):
|
|
|
|
|
|
|
|
|
|
|
|
def create_form(self):
|
|
|
|
def create_form(self):
|
|
|
|
bottom_frame = Frame(self.master, width=self.attr["width"], height=self.attr["height"] * 0.3)
|
|
|
|
bottom_frame = Frame(self.master, width=self.attr["width"], height=self.attr["height"] * 0.3)
|
|
|
|
self.func_input = Entry(bottom_frame, font=self.font_style, bg="#c0d9d9", width=40)
|
|
|
|
self.func_input = Entry(bottom_frame, font=self.font_style, width=40)
|
|
|
|
self.func_input.grid(row=0, column=0, columnspan=4, padx=30)
|
|
|
|
self.func_input.grid(row=0, column=0, columnspan=4, padx=30)
|
|
|
|
self.add_func_button = Button(bottom_frame, text="用户命名并新增基本函数", command=self.add_function, font=("Lucida Grande", 20))
|
|
|
|
self.add_func_button = Button(bottom_frame, text="用户命名并新增基本函数", command=self.add_function)
|
|
|
|
self.add_func_button.grid(row=0, column=4, padx=10)
|
|
|
|
self.add_func_button.grid(row=0, column=4, padx=10)
|
|
|
|
Label(bottom_frame, text="x步长", font=("Lucida Grande", 20)).grid(row=1, column=0, padx=30)
|
|
|
|
Label(bottom_frame, text="x步长", font=("Lucida Grande", 20)).grid(row=1, column=0, padx=30)
|
|
|
|
self.x_step = Entry(bottom_frame, font=self.font_style, bg="#c0d9d9", width=10)
|
|
|
|
self.x_step = Entry(bottom_frame, font=self.font_style, width=10)
|
|
|
|
self.x_step.grid(row=1, column=1, padx=10, pady=10)
|
|
|
|
self.x_step.grid(row=1, column=1, padx=10, pady=10)
|
|
|
|
Label(bottom_frame, text="x个数", font=("Lucida Grande", 20)).grid(row=1, column=2, padx=30)
|
|
|
|
Label(bottom_frame, text="x个数", font=("Lucida Grande", 20)).grid(row=1, column=2, padx=30)
|
|
|
|
self.x_count = Entry(bottom_frame, font=self.font_style, bg="#c0d9d9", width=10)
|
|
|
|
self.x_count = Entry(bottom_frame, font=self.font_style, width=10)
|
|
|
|
self.x_count.grid(row=1, column=3, padx=10, pady=10)
|
|
|
|
self.x_count.grid(row=1, column=3, padx=10, pady=10)
|
|
|
|
|
|
|
|
|
|
|
|
Label(bottom_frame, text="坐标轴", font=("Lucida Grande", 20)).grid(row=2, column=0, padx=30)
|
|
|
|
Label(bottom_frame, text="坐标轴", font=("Lucida Grande", 20)).grid(row=2, column=0, padx=30)
|
|
|
|
self.quadrant = IntVar()
|
|
|
|
self.quadrant = IntVar()
|
|
|
|
self.quadrant.set(4)
|
|
|
|
self.quadrant.set(4)
|
|
|
|
Radiobutton(bottom_frame, text="四象限", font=("Lucida Grande", 20), indicatoron=False, command=self.update_quadrant, value=4, variable=self.quadrant).grid(row=2, column=1, padx=10, pady=10)
|
|
|
|
Radiobutton(bottom_frame, text="四象限", command=self.update_quadrant, value=4, variable=self.quadrant).grid(row=2, column=1, padx=10, pady=10)
|
|
|
|
Radiobutton(bottom_frame, text="一象限", font=("Lucida Grande", 20), indicatoron=False, command=self.update_quadrant, value=1, variable=self.quadrant).grid(row=2, column=2, padx=10, pady=10)
|
|
|
|
Radiobutton(bottom_frame, text="一象限", command=self.update_quadrant, value=1, variable=self.quadrant).grid(row=2, column=2, padx=10, pady=10)
|
|
|
|
|
|
|
|
|
|
|
|
Label(bottom_frame, text="x放大倍数", font=("Lucida Grande", 20)).grid(row=3, column=0, padx=30)
|
|
|
|
Label(bottom_frame, text="x放大倍数", font=("Lucida Grande", 20)).grid(row=3, column=0, padx=30)
|
|
|
|
self.x_scale = Entry(bottom_frame, font=self.font_style, bg="#c0d9d9", width=10)
|
|
|
|
self.x_scale = Entry(bottom_frame, font=self.font_style, width=10)
|
|
|
|
self.x_scale.grid(row=3, column=1, padx=10, pady=10)
|
|
|
|
self.x_scale.grid(row=3, column=1, padx=10, pady=10)
|
|
|
|
Label(bottom_frame, text="y放大倍数", font=("Lucida Grande", 20)).grid(row=3, column=2, padx=30)
|
|
|
|
Label(bottom_frame, text="y放大倍数", font=("Lucida Grande", 20)).grid(row=3, column=2, padx=30)
|
|
|
|
self.y_scale = Entry(bottom_frame, font=self.font_style, bg="#c0d9d9", width=10)
|
|
|
|
self.y_scale = Entry(bottom_frame, font=self.font_style, width=10)
|
|
|
|
self.y_scale.grid(row=3, column=3, padx=10, pady=10)
|
|
|
|
self.y_scale.grid(row=3, column=3, padx=10, pady=10)
|
|
|
|
|
|
|
|
|
|
|
|
Button(bottom_frame, text="输出", font=("Lucida Grande", 20),
|
|
|
|
Button(bottom_frame, text="输出",
|
|
|
|
command=self.print_function, height=3, width=5).grid(row=1, rowspan=3, column=4, sticky="w")
|
|
|
|
command=self.print_function, width=5).grid(row=1, rowspan=3, column=4, sticky="w")
|
|
|
|
bottom_frame.place(x=0, y=self.attr["height"] * 0.65 + 20)
|
|
|
|
bottom_frame.place(x=0, y=self.attr["height"] * 0.65 + 20)
|
|
|
|
|
|
|
|
|
|
|
|
def show_user_function(self):
|
|
|
|
def show_user_function(self):
|
|
|
@ -380,7 +383,7 @@ class FunctionDisplay(Frame):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
root = Tk()
|
|
|
|
root = Window()
|
|
|
|
screenwidth = root.winfo_screenwidth()
|
|
|
|
screenwidth = root.winfo_screenwidth()
|
|
|
|
screenheight = root.winfo_screenheight()
|
|
|
|
screenheight = root.winfo_screenheight()
|
|
|
|
root_attr = {
|
|
|
|
root_attr = {
|
|
|
@ -392,4 +395,6 @@ if __name__ == '__main__':
|
|
|
|
root.geometry(alignstr)
|
|
|
|
root.geometry(alignstr)
|
|
|
|
root.resizable(width=False, height=False)
|
|
|
|
root.resizable(width=False, height=False)
|
|
|
|
app = FunctionDisplay(root, root_attr)
|
|
|
|
app = FunctionDisplay(root, root_attr)
|
|
|
|
|
|
|
|
ttk.Style().configure("TButton", font="-size 18")
|
|
|
|
|
|
|
|
ttk.Style().configure("TRadiobutton", font="-size 18")
|
|
|
|
root.mainloop()
|
|
|
|
root.mainloop()
|
|
|
|