python,圖形界面編程,tkinter,實現一個最簡單的加法計算器的圖形界面小程序


from tkinter import *
def Calculate():
    a1 = int(text1.get('1.0', END))  # 從行首取到行尾
    a2 = int(text2.get('1.0', END))
    a3 = a1 + a2
    text3.delete('1.0', END)
    text3.insert(INSERT, a3)

root = Tk()
root.title('myTitle')
label1 = Label(root, text = 'First Number:')
label1.grid(row = 0, column = 0)
text1 = Text(root, width = 30, height = 1)
text1.grid(row= 1, column = 0)
label2 = Label(root, text = 'Second Number:')
label2.grid(row = 2, column = 0)
text2 = Text(root, width = 30, height = 1)
text2.grid(row = 3, column = 0)
label3 = Label(root, text = 'Result:')
label3.grid(row = 4, column = 0)
text3 = Text(root, width = 30, height = 1)
text3.grid(row = 5, column = 0)
button1 = Button(root, text = 'Calculate', command = Calculate)
button1.grid(row = 6, column = 0)
mainloop()

  運行結果顯示:

 

 這是最簡單的一個利用tkinter包實現的小程序, 實現了輸入數據,計算求和並顯示計算結果的功能。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM