Python tkinter實現(xiàn)簡單加法計算器代碼實例
tkinter 是 Python 的標(biāo)準(zhǔn) GUI 庫。Python 使用 tkinter 可以快速的創(chuàng)建 GUI 應(yīng)用程序。由于 tkinter 是內(nèi)置到 python 的安裝包中、只要安裝好 Python 之后就能 import tkinter 庫、而且 IDLE 也是用 tkinter 編寫而成、對于簡單的圖形界面 tkinter 還是能應(yīng)付自如。
代碼如下
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()
運行結(jié)果顯示:
這是最簡單的一個利用tkinter包實現(xiàn)的小程序, 實現(xiàn)了輸入數(shù)據(jù),計算求和并顯示計算結(jié)果的功能。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JAMon(Java Application Monitor)備忘記2. js的一些潛在規(guī)則使用分析3. JDBC連接數(shù)據(jù)庫經(jīng)驗集萃4. Python基于pyjnius庫實現(xiàn)訪問java類5. NetCore 配置Swagger的詳細代碼6. ASP.Net MVC利用NPOI導(dǎo)入導(dǎo)出Excel的示例代碼7. Python PyQt5中彈出子窗口解決子窗口一閃而過的問題8. 讓chatgpt將html中的圖片轉(zhuǎn)為base64方法示例9. 如何用 Python 制作一個迷宮游戲10. django 獲取字段最大值,最新的記錄操作
