Python tkinter實(shí)現(xiàn)簡(jiǎn)單加法計(jì)算器代碼實(shí)例
tkinter 是 Python 的標(biāo)準(zhǔn) GUI 庫(kù)。Python 使用 tkinter 可以快速的創(chuàng)建 GUI 應(yīng)用程序。由于 tkinter 是內(nèi)置到 python 的安裝包中、只要安裝好 Python 之后就能 import tkinter 庫(kù)、而且 IDLE 也是用 tkinter 編寫(xiě)而成、對(duì)于簡(jiǎn)單的圖形界面 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()
運(yùn)行結(jié)果顯示:

這是最簡(jiǎn)單的一個(gè)利用tkinter包實(shí)現(xiàn)的小程序, 實(shí)現(xiàn)了輸入數(shù)據(jù),計(jì)算求和并顯示計(jì)算結(jié)果的功能。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python?tkinter實(shí)現(xiàn)計(jì)算器功能
- 如何利用python的tkinter實(shí)現(xiàn)一個(gè)簡(jiǎn)單的計(jì)算器
- Python+tkinter使用40行代碼實(shí)現(xiàn)計(jì)算器功能
- Python Tkinter實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能
- python使用tkinter實(shí)現(xiàn)簡(jiǎn)單計(jì)算器
- Python+tkinter使用80行代碼實(shí)現(xiàn)一個(gè)計(jì)算器實(shí)例
- 利用Tkinter(python3.6)實(shí)現(xiàn)一個(gè)簡(jiǎn)單計(jì)算器
- Python編程使用tkinter模塊實(shí)現(xiàn)計(jì)算器軟件完整代碼示例
- 基于python的Tkinter實(shí)現(xiàn)一個(gè)簡(jiǎn)易計(jì)算器
- python tkinter實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
相關(guān)文章
關(guān)于Matplotlib繪制動(dòng)態(tài)實(shí)時(shí)曲線(xiàn)的方法改進(jìn)指南
這篇文章主要給大家介紹了關(guān)于Matplotlib繪制動(dòng)態(tài)實(shí)時(shí)曲線(xiàn)的相關(guān)資料,matplotlib是python里最popular的畫(huà)圖工具,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-06-06
解決pytorch rnn 變長(zhǎng)輸入序列的問(wèn)題
這篇文章主要介紹了解決pytorch rnn 變長(zhǎng)輸入序列的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05
python用列表生成式寫(xiě)嵌套循環(huán)的方法
python中字典元素的創(chuàng)建、獲取和遍歷等字典知識(shí)點(diǎn)
keras讀取訓(xùn)練好的模型參數(shù)并把參數(shù)賦值給其它模型詳解
Python Flask利用SocketIO庫(kù)實(shí)現(xiàn)圖表的繪制

