Python tkinter實現簡單加法計算器代碼實例
tkinter 是 Python 的標準 GUI 庫。Python 使用 tkinter 可以快速的創建 GUI 應用程序。由于 tkinter 是內置到 python 的安裝包中、只要安裝好 Python 之后就能 import tkinter 庫、而且 IDLE 也是用 tkinter 編寫而成、對于簡單的圖形界面 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包實現的小程序, 實現了輸入數據,計算求和并顯示計算結果的功能。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. jQuery加PHP實現圖片上傳并提交的示例代碼2. Idea 2020.2安裝MyBatis Log Plugin 不可用的解決方法3. IDEA怎么切換Git分支的實現方法4. 解決idea刪除模塊后重新創建顯示該模塊已經被注冊的問題5. 完美實現浮動元素橫排居中顯示6. JSP Tag Library-AjaxTags 1.0, released7. 小區后臺管理系統項目前端html頁面模板實現示例8. Python使用ElementTree美化XML格式的操作9. jsp request.getParameter() 和request.getAttribute()方法區別詳解10. JSP動態網頁開發技術概述
