from tkinter import *
from tkinter.messagebox import *
def show_answer():
sum1=0
for I in range (int(num1.get()),int(num2.get())+1,int(num3.get())):
sum1=sum1 + I
sum1 = "{:.1f}".format(sum1)
blank1.delete('0', END)
blank1.insert(0, sum1)
main = Tk()
main.title("Tkinter 迴圈作連加法 ")
Label(main, text = "輸入起始值 :").grid(row=0)
Label(main, text = "輸入結束值 :").grid(row=2)
Label(main, text = "輸入間距值 :").grid(row=4)
Label(main, text = "連加值 = ").grid(row=6)
num1 = Entry(main)
num2 = Entry(main)
num3 = Entry(main)
blank1 = Entry(main)
num1.grid(row=0, column=1)
num2.grid(row=2, column=1)
num3.grid(row=4, column=1)
blank1.grid(row=6, column=1)
Button(main, text='離開', command=main.destroy).grid(row=8, column=0, sticky=W, pady=4)
Button(main, text='計算', command=show_answer).grid(row=8, column=1, sticky=W, pady=4)
mainloop()
沒有留言:
張貼留言