如何将计算器GUI连接到图形GUI?

时间:2018-11-26 11:12:09

标签: python graph calculator

我想将计算器gui与功能图gui连接起来。 例如 如果我单击计算器上的“ sinx”,则图形(正弦函数)将出现在图形gui上。 我该怎么办?

  1. 计算器GUI代码

    从tkinter导入*     窗口= Tk()     window.title(“해대비주얼”)     ''     top_row =框架(窗口)     top_row.grid(行= 0,列= 0,列跨度= 2,粘性= N)     显示=条目(顶行,宽度= 35,bg =“浅蓝色”)     display.grid()

    num_pad = Frame(window)
    num_pad.grid(row=1, column=0, sticky=W)
    num_pad_list = [
        '7','8','9',
        '4','5','6',
        '1','2','3',
        '0','.','=']
    r = 0
    c = 0
    for btn_text in num_pad_list:
        def cmd(x=btn_text):
            click(x)
        Button(num_pad, text=btn_text, width=5, command=cmd).grid(row=r, column=c)
        c = c + 1
        if c > 2:
            c = 0
            r = r + 1
    
    
    
    
    operator = Frame(window)
    operator.grid(row=1, column=1, sticky=E)
    operator_list = [
        '*','/',
        '+','-',
        '(',')',
        '^','C']
    r = 0
    c = 0
    for btn_text in operator_list:
        def cmd(x=btn_text):
            click(x)
        Button(operator, text=btn_text, width=5, command=cmd).grid(row=r, column=c)
        c = c + 1
        if c > 1:
            c = 0
            r = r + 1
    
    
    
    etc = Frame(window)
    etc.grid(row=50, column=0, sticky=S)
    etc_list = ['pi','sin','cos','x']
    r = 0
    c = 0
    for btn_text in etc_list:
        def cmd(x=btn_text):
            click(x)
        Button(etc, text=btn_text, width=5, command=cmd).grid(row=r, column=c)
        r = 0
        c = c + 1
    
    def click(key):
        if key == "=":
            try:
                if "^" in display.get():
                    n = display.get().split(sep="^")
                    result = str(float(n[0]) ** float(n[1]))
                    display.insert(END, " = " + result)
                else:
                    result = str(eval(display.get()))[0:10]
                    display.insert(END, " = " + result)
            except:
                display.insert(END, " --> Error!")
        elif key == "C":
            display.delete(0, END)
        elif key == etc_list[0]:
            import math
            display.insert(END, math.pi)
        else:
            display.insert(END, key)
    
    
    window.mainloop()
    

2.Graph GUI代码

 from tkinter import *
    graph = Tk()
    graph.title("해대비주얼 그래프")
    ''
    graph.geometry("1000x700")
    ''

0 个答案:

没有答案