

jupyterのpythonで関数電卓のプログラムを組んだのですが、その電卓から手入力をしてグラフを描写したいです。

matplotを使用して電卓プログラムの後に関数をグラフに描写するプログラムを書いた方が良いのでしょうか？下記のプログラムで関数プログラムを書いてから関数のプログラムを書いたら実行を終了したら表示されました。

[code]

    import math
    import tkinter as tk
    import matplotlib.pyplot as plt
    %matplotlib inline
    
    class Application(tk.Frame):
    
        def __init__(self, master=None):
            super().__init__(master)
            self.master.geometry('500x700')
    
            self.master.title('計算機')
    
            self.entry = tk.Entry(self.master, justify="right")
    
            self.menu_bar = tk.Menu(self.master)
            self.master.config(menu=self.menu_bar)
    
            self.create_widgets()
    
    
        def input(self, action):
            self.entry.insert(tk.END, action)
    
        def clear_all(self):
            self.entry.delete(0, tk.END)
    
        def clear_one(self):
            txt = self.entry.get()
            self.entry.delete(0, tk.END)
            self.entry.insert(0, txt[:-1])
    
        def entered_value(self):
            return eval(self.entry.get().replace('÷', '/').replace('x', '*').replace('%', '/100').replace('^','**').replace('√','**0.5').replace('e','math.e'))
    
        def equals(self):
            self.value = self.entered_value()
            self.entry.delete(0, tk.END)
            self.entry.insert(0, self.value)
    
        def unary(self, function):
            self.value = function(self.entered_value())
            self.entry.delete(0, tk.END)
            self.entry.insert(0, self.value)
    
        def create_widgets(self):
            file_menu = tk.Menu(self.menu_bar)
            file_menu.add_command(label='閉じる', command=self.master.quit)
            self.menu_bar.add_cascade(label='メニュー', menu=file_menu)
    
            self.entry.grid(row=0, column=0, columnspan=4, pady=3)
            self.entry.focus_set()
    
            tk.Button(self.master, text='7', width=7,
                      command=lambda: self.input(7)).grid(row=2, column=0)
            tk.Button(self.master, text='8', width=7,
                      command=lambda: self.input(8)).grid(row=2, column=1)
            tk.Button(self.master, text='9', width=7,
                      command=lambda: self.input(9)).grid(row=2, column=2)
    
            tk.Button(self.master, text='4', width=7,
                      command=lambda: self.input(4)).grid(row=3, column=0)
            tk.Button(self.master, text='5', width=7,
                      command=lambda: self.input(5)).grid(row=3, column=1)
            tk.Button(self.master, text='6', width=7,
                      command=lambda: self.input(6)).grid(row=3, column=2)
    
            tk.Button(self.master, text='1', width=7,
                      command=lambda: self.input(1)).grid(row=4, column=0)
            tk.Button(self.master, text='2', width=7,
                      command=lambda: self.input(2)).grid(row=4, column=1)
            tk.Button(self.master, text='3', width=7,
                      command=lambda: self.input(3)).grid(row=4, column=2)
    
            tk.Button(self.master, text='0', width=12,
                      command=lambda: self.input(0)).grid(row=5, column=0, columnspan=2)
            tk.Button(self.master, text='.', width=7,
                      command=lambda: self.input('.')).grid(row=5, column=2)
            tk.Button(self.master, text='=', width=7,
                      command=self.equals).grid(row=5, column=3)
    
            tk.Button(self.master, text='x', width=7,
                      command=lambda: self.input('x')).grid(row=2, column=3)
            tk.Button(self.master, text='-', width=7,
                      command=lambda: self.input('-')).grid(row=3, column=3)
            tk.Button(self.master, text='+', width=7,
                      command=lambda: self.input('+')).grid(row=4, column=3)
    
            tk.Button(self.master, text='AC', width=7,
                      command=lambda: self.clear_all()).grid(row=1, column=0)
            tk.Button(self.master, text='C', width=7,
                      command=lambda: self.clear_one()).grid(row=1, column=1)
            tk.Button(self.master, text='%', width=7,
                      command=lambda: self.input('%')).grid(row=1, column=2)
            tk.Button(self.master, text='÷', width=7,
                      command=lambda: self.input('÷')).grid(row=1, column=3)
    
            tk.Button(self.master, text='sin', width=7,
                      command=lambda: self.unary(math.sin)).grid(row=1, column=5)
            tk.Button(self.master, text='cos', width=7,
                      command=lambda: self.unary(math.cos)).grid(row=2, column=5)
            tk.Button(self.master, text='tan', width=7,
                      command=lambda: self.unary(math.tan)).grid(row=3, column=5)
            tk.Button(self.master, text='log', width=7,
                      command=lambda: self.unary(math.log10)).grid(row=4, column=5)
    
            tk.Button(self.master, text='^', width=7,
                     command=lambda: self.input('^')).grid(row=1,column=4)
            tk.Button(self.master, text='π', width=7,
                     command=lambda: self.input(math.pi)).grid(row=2,column=4)
            tk.Button(self.master, text='√', width=7,
                     command=lambda: self.input('√')).grid(row=3,column=4)
            tk.Button(self.master, text='e', width=7,
                     command=lambda: self.input('e')).grid(row=4,column=4)
            tk.Button(self.master, text='!', width=7,
                     command=lambda: self.unary(math.factorial)).grid(row=5,column=4)
    
    fig = plt.figure()
    X = fig.add_subplot(221)
    
    X.plot()
    
    plt.show()
    
    root = tk.Tk()
    app = Application(master=root)
    app.mainloop()
    
[/code]


CC BY-SA 4.0
2020-09-03T00:05:14.887
70092
2020-09-03T00:16:27.787
2020-09-03T00:16:27.787
3060
41748
question
python python3 jupyter-notebook
関数電卓から手入力で関数グラフを描写したい