劉任昌eval函數圖形介面計算機

W3SHOOLS

模仿美國男生計算機程式碼

from tkinter import *
def button_press(num):
    global equation_text
    equation_text = equation_text + str(num)
    equation_label.set(equation_text)
def equals():
    global equation_text
    try:
        total = str(eval(equation_text))
        equation_label.set(total)
        equation_text = total
    except SyntaxError:
        equation_label.set("syntax error")
        equation_text = ""
    except ZeroDivisionError:
        equation_label.set("arithmetic error")
        equation_text = ""
def clear():
    global equation_text
    equation_label.set("")
    equation_text = ""
window = Tk()
window.title("劉任昌模仿美國人的計算")
window.geometry("500x500")
equation_text = ""
equation_label = StringVar()
label = Label(window, textvariable=equation_label, font=('consolas',20), bg="white", width=24, height=2)
label.pack()
frame = Frame(window)
frame.pack()
button1 = Button(frame, text=1, height=4, width=9, font=60,bg='#11ff11',
                 command=lambda: button_press(1))
button1.grid(row=0, column=0)
button2 = Button(frame, text=2, height=4, width=9, font=60,bg='#0000ff',fg='#ffffff',
                 command=lambda: button_press(2))
button2.grid(row=0, column=1)

button3 = Button(frame, text=3, height=4, width=9, font=35,
                 command=lambda: button_press(3))
button3.grid(row=0, column=2)

button4 = Button(frame, text=4, height=4, width=9, font=35,
                 command=lambda: button_press(4))
button4.grid(row=1, column=0)

button5 = Button(frame, text=5, height=4, width=9, font=35,
                 command=lambda: button_press(5))
button5.grid(row=1, column=1)

button6 = Button(frame, text=6, height=4, width=9, font=35,
                 command=lambda: button_press(6))
button6.grid(row=1, column=2)

button7 = Button(frame, text=7, height=4, width=9, font=35,
                 command=lambda: button_press(7))
button7.grid(row=2, column=0)

button8 = Button(frame, text=8, height=4, width=9, font=35,
                 command=lambda: button_press(8))
button8.grid(row=2, column=1)

button9 = Button(frame, text=9, height=4, width=9, font=35,
                 command=lambda: button_press(9))
button9.grid(row=2, column=2)

button0 = Button(frame, text=0, height=4, width=9, font=35,
                 command=lambda: button_press(0))
button0.grid(row=3, column=0)

plus = Button(frame, text='+', height=4, width=9, font=35,
                 command=lambda: button_press('+'))
plus.grid(row=0, column=3)

minus = Button(frame, text='-', height=4, width=9, font=35,
                 command=lambda: button_press('-'))
minus.grid(row=1, column=3)

multiply = Button(frame, text='*', height=4, width=9, font=35,
                 command=lambda: button_press('*'))
multiply.grid(row=2, column=3)

divide = Button(frame, text='/', height=4, width=9, font=35,
                 command=lambda: button_press('/'))
divide.grid(row=3, column=3)
equal = Button(frame, text='=', height=4, width=9, font=35,
                 command=equals)
equal.grid(row=3, column=2)
decimal = Button(frame, text='.', height=4, width=9, font=35,
                 command=lambda: button_press('.'))
decimal.grid(row=3, column=1)
clear = Button(window, text='clear', height=4, width=12, font=35,
                 command=clear)
clear.pack()
window.mainloop()

印度女生拷貝github

git怪胎hub匯集github目前微軟維護,gitub
from tkinter import *
from unittest import result


def buttonClick(number):
    global operator
    operator = operator + str(number)
    input_value.set(operator)


def buttonClear():
    global operator
    operator = ""
    input_value.set("")


def buttonEqual():
    global operator
    result = str(eval(operator))
    input_value.set(result)
    operator = ""


main = Tk()
main.title("劉任昌改寫自印度女生的程式碼")
operator = ""
input_value = StringVar()
display_text = Entry(main, font=("arial", 20, "bold"), textvariable=input_value, bd=30, insertwidth=4,
                     justify=RIGHT)
display_text.grid(columnspan=4)
# Row 1 7 8 9 +
btn_7 = Button(main, padx=16, bd=8, fg="gray",
               font=("arial", 20, "bold"), text="7", command=lambda: buttonClick(7))
btn_7.grid(row=1, column=0)
btn_8 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="8", command=lambda: buttonClick(8))
btn_8.grid(row=1, column=1)

btn_9 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="9", command=lambda: buttonClick(9))
btn_9.grid(row=1, column=2)

btn_add = Button(main, padx=16, bd=8, fg="black",
                 font=("arial", 20, "bold"), text="+", command=lambda: buttonClick("+"))
btn_add.grid(row=1, column=3)
btn_4 = Button(main, padx=16, bd=8, fg="black",bg='#99ff33',
               font=("arial", 20, "bold"), text="4", command=lambda: buttonClick(4))
btn_4.grid(row=2, column=0)

btn_5 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="5", command=lambda: buttonClick(5))
btn_5.grid(row=2, column=1)

btn_6 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="6", command=lambda: buttonClick(6))
btn_6.grid(row=2, column=2)

btn_sub = Button(main, padx=16, bd=8, fg="black",
                 font=("arial", 20, "bold"), text="-", command=lambda: buttonClick("-"))
btn_sub.grid(row=2, column=3)
# Row 3 - 1 2 3 *以下第3列row=3,第0欄column=0,排列0,1,2,3
btn_1 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="4", command=lambda: buttonClick(1))
btn_1.grid(row=3, column=0)

btn_2 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="5", command=lambda: buttonClick(2))
btn_2.grid(row=3, column=1)

btn_3 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="6", command=lambda: buttonClick(3))
btn_3.grid(row=3, column=2)
btn_mul = Button(main, padx=16, bd=8, fg="black",
                 font=("arial", 20, "bold"), text="*", command=lambda: buttonClick("*"))
btn_mul.grid(row=3, column=3)
# Row 4 - 0 C = /
btn_0 = Button(main, padx=16, bd=8, fg="black",
               font=("arial", 20, "bold"), text="0", command=lambda: buttonClick(0))
btn_0.grid(row=4, column=0)
btn_clear = Button(main, padx=16, bd=8, fg="black",bg='#00ffff',
                   font=("arial", 20, "bold"), text="清除", command=buttonClear)
btn_clear.grid(row=4, column=1)
btn_equal = Button(main, padx=16, bd=8, fg="black",
                   font=("arial", 20, "bold"), text="=", command=buttonEqual)
btn_equal.grid(row=4, column=2)

btn_div = Button(main, padx=16, bd=8, fg="black",
                 font=("arial", 20, "bold"), text="/", command=lambda: buttonClick("/"))
btn_div.grid(row=4, column=3)
main.mainloop()

留言

  1. https://hsiao-yu0711.blogspot.com/2024/05/blog-post_22.html

    回覆刪除
  2. https://ruubyyy0.blogspot.com/2024/05/guieval.html

    回覆刪除
  3. https://11217133.blogspot.com/2024/05/guieval.html

    回覆刪除
  4. https://meimei20041026.blogspot.com/2024/05/eval.html

    回覆刪除
  5. https://xi-xbox-mmi.blogspot.com/2024/05/blog-post_22.html

    回覆刪除
  6. https://ccp19890604.blogspot.com/2024/05/eval.html

    回覆刪除
  7. https://the-dumbest-one.blogspot.com/2024/05/eval.html

    回覆刪除
  8. https://fanyahui.blogspot.com/2024/05/blog-post_22.html

    回覆刪除
  9. https://the-most-great-hsing-tsen.blogspot.com/2024/05/eval.html

    回覆刪除
  10. https://earnest-person.blogspot.com/2024/05/eval.html

    回覆刪除
  11. https://the-most-beautifui666.blogspot.com/2024/05/eval.html

    回覆刪除
  12. https://doryee00000000.blogspot.com/2024/05/blog-post.html

    回覆刪除
  13. https://chen0119.blogspot.com/2024/05/evalevaluatecalculator.html

    回覆刪除
  14. https://lukelu0928.blogspot.com/2024/05/evalecaluatecalculator.html

    回覆刪除
  15. https://www.blogger.com/blog/post/edit/preview/7449986463321468050/5391184062426637082

    回覆刪除
  16. https://czaudi1001.blogspot.com/2024/05/eval-evalustecalcuste.html

    回覆刪除
  17. https://s10655075.blogspot.com/2024/05/eval.html

    回覆刪除
  18. https://the-most-great-chenxi.blogspot.com/2024/06/eval.html

    回覆刪除
  19. https://the-most-beeaut.blogspot.com/2024/06/from-tkinter-import-def-buttonpressnum.html

    回覆刪除
  20. https://the-most-great-tony11.blogspot.com/2024/06/from-tkinter-import-def-buttonpressnum.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

劉任昌大語言模型協助收集簡報的資料

劉任昌w3schools學習ASCII, Emoji與Javascript迴圈

劉任昌HTML,CSS,樣式style,嵌入iframe