2017年10月2日 星期一

Tkinter 四則運算


from tkinter import *
from tkinter.messagebox import *

def show_answer():
   Ans1 = int(num11.get()) + int(num12.get())
   blank1.delete('0', END)
   blank1.insert(0, Ans1)

   Ans2 = int(num21.get()) - int(num22.get())
   blank2.delete('0', END)
   blank2.insert(0, Ans2)

   Ans3 = int(num31.get()) * int(num32.get())
   blank3.delete('0', END)
   blank3.insert(0, Ans3)

   Ans4 = int(num41.get()) / int(num42.get())
   blank4.delete('0', END)
   blank4.insert(0, Ans4)
   

main = Tk()
main.title("Tkinter 四則運算 加減乘除法  ")
main.geometry("300x200")

Label(main, text = "Enter Num 1:").grid(row=0)
Label(main, text = "Enter Num 2:").grid(row=1)
Label(main, text = " 和 =").grid(row=2)
Label(main, text = " 差 =").grid(row=2,column=2)
Label(main, text = "乘積=").grid(row=2,column=4)
Label(main, text = " 商 =").grid(row=2,column=6)


num11 = Entry(main)
num12 = Entry(main)
blank1 = Entry(main)

num21 = Entry(main)
num22 = Entry(main)
blank2 = Entry(main)

num31 = Entry(main)
num32 = Entry(main)
blank3 = Entry(main)

num41 = Entry(main)
num42 = Entry(main)
blank4 = Entry(main)



num11.grid(row=0, column=1)
num12.grid(row=1, column=1)
blank1.grid(row=2, column=1)

num21.grid(row=0, column=3)
num22.grid(row=1, column=3)
blank2.grid(row=2, column=3)


num31.grid(row=0, column=5)
num32.grid(row=1, column=5)
blank3.grid(row=2, column=5)


num41.grid(row=0, column=7)
num42.grid(row=1, column=7)
blank4.grid(row=2, column=7)



Button(main, text='Quit', command=main.destroy).grid(row=4, column=0, sticky=W, pady=4)
Button(main, text='Show', command=show_answer).grid(row=4, column=1, sticky=W, pady=4)

mainloop()


沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...