欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)GUI計(jì)算器(附源碼)

 更新時(shí)間:2022年11月06日 08:24:42   作者:川川菜鳥  
這篇文章主要為大家詳細(xì)介紹了如何利用Python語言實(shí)現(xiàn)GUI計(jì)算器,可執(zhí)行復(fù)雜運(yùn)算,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下

效果

可執(zhí)行正常加減乘除相關(guān)運(yùn)算,源碼已貼,自行測試。

源碼

# coding=gbk
"""
作者:川川
@時(shí)間  : 2022/11/6 3:10
"""
from tkinter import *

calc = Tk()
calc.title('川川計(jì)算器')
operator = ''

def clear():
    global operator
    operator=''
    txt_input.set("")
    display.insert(0,'開始計(jì)算...')

def button_press(number_or_operator):
    global operator
    operator = operator+str(number_or_operator)
    txt_input.set(operator)

def equal():
    global operator
    result = float(eval(operator))
    txt_input.set(result)
    operator=''


txt_input =StringVar(value='開始計(jì)算...')

#-----------------DISPLAY-----------------------------------
display = Entry(calc,font =('arial',30),fg='white',bg='green'
                ,justify='right',bd='50',textvariable=txt_input)
display.grid(columnspan=4)

#------------------row 1--------------------------------------

button7 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='7',command=lambda:button_press(7)).grid(row=1,column=0)
button8 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='8',command=lambda:button_press(8)).grid(row=1,column=1)
button9 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='9',command=lambda:button_press(9)).grid(row=1,column=2)
button_clear = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='green',
                 font=('arial',30,'bold'),text='C',command=clear).grid(row=1,column=3)

#------------------row 2--------------------------------------

button4 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='4',command=lambda:button_press(4)).grid(row=2,column=0)
button5 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='5',command=lambda:button_press(5)).grid(row=2,column=1)
button6 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='6',command=lambda:button_press(6)).grid(row=2,column=2)
button_plus = Button(calc,padx =34,pady =12,bd=8,fg='black',bg='orange',
                 font=('arial',30,'bold'),text='+',command=lambda:button_press('+')).grid(row=2,column=3)

#------------------row 3--------------------------------------

button1 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='1',command=lambda:button_press(1)).grid(row=3,column=0)
button2 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='2',command=lambda:button_press(2)).grid(row=3,column=1)
button3 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='3',command=lambda:button_press(3)).grid(row=3,column=2)
button_minus = Button(calc,padx =38,pady =12,bd=8,fg='black',bg='orange',
                 font=('arial',30,'bold'),text='-',command=lambda:button_press('-')).grid(row=3,column=3)

#------------------row 4--------------------------------------

button_0 = Button(calc,padx =30,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='0',command=lambda:button_press(0)).grid(row=4,column=0)
button_dot = Button(calc,padx =36,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='.',command=lambda:button_press('.')).grid(row=4,column=1)
button_divide = Button(calc,padx =36,pady =12,bd=8,fg='black',bg='orange',
                 font=('arial',30,'bold'),text='/',command=lambda:button_press('/')).grid(row=4,column=2)
button_mult = Button(calc,padx =38,pady =12,bd=8,fg='black',bg='orange',
                 font=('arial',30,'bold'),text='*',command=lambda:button_press('*')).grid(row=4,column=3)

#------------------row 5--------------------------------------

button_equal = Button(calc,padx =95,pady =12,bd=8,fg='black',bg='green',
                 font=('arial',30,'bold'),text='=',command=equal).grid(row=5,column=0,columnspan=2)
button_open = Button(calc,padx =35,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text='(',command=lambda:button_press('(')).grid(row=5,column=2)
button_close = Button(calc,padx =38,pady =12,bd=8,fg='black',bg='white',
                 font=('arial',30,'bold'),text=')',command=lambda:button_press(')')).grid(row=5,column=3)

calc.mainloop()

到此這篇關(guān)于Python實(shí)現(xiàn)GUI計(jì)算器(附源碼)的文章就介紹到這了,更多相關(guān)Python GUI計(jì)算器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • pandas讀取HTML和JSON數(shù)據(jù)的實(shí)現(xiàn)示例

    pandas讀取HTML和JSON數(shù)據(jù)的實(shí)現(xiàn)示例

    Pandas可以直接讀取html和JSON數(shù)據(jù),本文就來介紹一下pandas讀取HTML和JSON數(shù)據(jù)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),感興趣的可以了解一下
    2024-01-01
  • pyspark給dataframe增加新的一列的實(shí)現(xiàn)示例

    pyspark給dataframe增加新的一列的實(shí)現(xiàn)示例

    這篇文章主要介紹了pyspark給dataframe增加新的一列的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • python 爬蟲網(wǎng)頁登陸的簡單實(shí)現(xiàn)

    python 爬蟲網(wǎng)頁登陸的簡單實(shí)現(xiàn)

    這篇文章主要介紹了python 爬蟲網(wǎng)頁登陸的簡單實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Python集合pop()函數(shù)使用方法詳解

    Python集合pop()函數(shù)使用方法詳解

    這篇文章主要介紹了Python 集合 pop()函數(shù)的使用方法,文中有詳細(xì)的代碼實(shí)例,講解的非常清楚,具有一定的參考價(jià)值,需要的朋友可以參考下
    2023-07-07
  • Python函數(shù)參數(shù)匹配模型通用規(guī)則keyword-only參數(shù)詳解

    Python函數(shù)參數(shù)匹配模型通用規(guī)則keyword-only參數(shù)詳解

    Python3對(duì)函數(shù)參數(shù)的排序規(guī)則更加通用化了,即Python3 keyword-only參數(shù),該參數(shù)即為必須只按照關(guān)鍵字傳遞而不會(huì)有一個(gè)位置參數(shù)來填充的參數(shù)。這篇文章主要介紹了Python函數(shù)參數(shù)匹配模型通用規(guī)則keyword-only參數(shù),需要的朋友可以參考下
    2019-06-06
  • python?selenium在打開的瀏覽器中動(dòng)態(tài)調(diào)整User?Agent

    python?selenium在打開的瀏覽器中動(dòng)態(tài)調(diào)整User?Agent

    這篇文章主要介紹的是python?selenium在打開的瀏覽器中動(dòng)態(tài)調(diào)整User?Agent,具體相關(guān)資料請需要的朋友參考下面文章詳細(xì)內(nèi)容,希望對(duì)你有所幫助
    2022-02-02
  • python cv2在驗(yàn)證碼識(shí)別中應(yīng)用實(shí)例解析

    python cv2在驗(yàn)證碼識(shí)別中應(yīng)用實(shí)例解析

    這篇文章主要介紹了python cv2在驗(yàn)證碼識(shí)別中應(yīng)用實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • Python輕松實(shí)現(xiàn)2位小數(shù)隨機(jī)生成

    Python輕松實(shí)現(xiàn)2位小數(shù)隨機(jī)生成

    在Python中,我們經(jīng)常需要生成隨機(jī)數(shù),特別是2位小數(shù)的隨機(jī)數(shù),這在模擬實(shí)驗(yàn)、密碼學(xué)、游戲開發(fā)等領(lǐng)域都很有用,下面是如何在Python中生成2位小數(shù)的隨機(jī)數(shù)的代碼示例,需要的朋友可以參考下
    2023-11-11
  • python之隨機(jī)數(shù)函數(shù)的實(shí)現(xiàn)示例

    python之隨機(jī)數(shù)函數(shù)的實(shí)現(xiàn)示例

    這篇文章主要介紹了python之隨機(jī)數(shù)函數(shù)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • OpenAI?Function?Calling特性示例詳解

    OpenAI?Function?Calling特性示例詳解

    這篇文章主要為大家介紹了OpenAI?Function?Calling特性作用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07

最新評(píng)論