Python Tkinter 圓形面積計算
請撰寫一程式,輸入一圓的半徑,並加以計算此圓之面積和周長,最後請印出此圓的半徑(Radius)、周長(Perimeter)和面積(Area)。
'''
請撰寫一程式,輸入一圓的半徑,並加以計算此圓之面積和周長,
最後請印出此圓的半徑(Radius)、周長(Perimeter)和面積(Area)。
'''
def exit():
root.destroy()
def convert():
radius = int(e1.get())
Perimeter = round((2 * math.pi * radius),2)
Area= round((math.pi * radius ** 2),2)
t1.config(state='normal')
t1.delete('1.0', tk.END)
t1.insert(tk.END,radius)
t1.config(state='disabled')
t2.config(state='normal')
t2.delete('1.0', tk.END)
t2.insert(tk.END,Perimeter)
t2.config(state='disabled')
t3.config(state='normal')
t3.delete('1.0', tk.END)
t3.insert(tk.END,Area)
t3.config(state='disabled')
import math
import tkinter as tk
root = tk.Tk()
root.geometry("640x320")
root.config(bg="#A569BD")
root.resizable(width=False,height=False)
root.title('圓形面積計算')
l1= tk.Label(root,text="輸入半徑 Radius: ",font=("Arial", 10,"bold"),fg="white",bg="#A569BD")
l2= tk.Label(root,text="半徑(Radius)為 : ",font=("Arial", 10,"bold"),fg="white",bg="#A569BD")
l3= tk.Label(root,text="周長(Perimeter)為 : ",font=("Arial", 10,"bold"),fg="white",bg="#A569BD")
l4= tk.Label(root,text="面積(Area)為 : ",font=("Arial", 10,"bold"),fg="white",bg="#A569BD")
empty_l1 = tk.Label(root,bg="#A569BD")
empty_l2 = tk.Label(root,bg="#A569BD")
empty_l3 = tk.Label(root,bg="#A569BD")
empty_l4 = tk.Label(root,bg="#A569BD")
empty_l5 = tk.Label(root,bg="#A569BD")
e1= tk.Entry(root,font=('Arial',10))
btn1 = tk.Button(root,text="計算",font=("Arial", 10),command=convert)
btn2 = tk.Button(root,text="離開",font=("Arial", 10),command=exit)
t1=tk.Text(root,state="disabled",width=15,height=0)
t2=tk.Text(root,state="disabled",width=15,height=0)
t3=tk.Text(root,state="disabled",width=15,height=0)
l1.pack()
e1.pack()
empty_l1.pack()
btn1.pack()
l2.pack()
t1.pack()
empty_l2.pack()
l3.pack()
t2.pack()
empty_l3.pack()
l4.pack()
t3.pack()
empty_l4.pack()
btn2.pack()
root.mainloop()
沒有留言:
張貼留言