最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實現(xiàn)GUI計算器(附源碼)

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

效果

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

源碼

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

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

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

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='開始計算...')

#-----------------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實現(xiàn)GUI計算器(附源碼)的文章就介紹到這了,更多相關(guān)Python GUI計算器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python里將list中元素依次向前移動一位

    python里將list中元素依次向前移動一位

    這篇文章主要介紹了python里將list中元素依次向前移動一位,以及使用racket 5.2.1實現(xiàn)此功能的代碼,希望對大家有所幫助
    2014-09-09
  • 在python image 中安裝中文字體的實現(xiàn)方法

    在python image 中安裝中文字體的實現(xiàn)方法

    今天小編大家分享一篇在python image 中安裝中文字體的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • pycharm安裝圖文教程

    pycharm安裝圖文教程

    這篇文章主要為大家詳細介紹了pycharm安裝圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Python使用cn2an實現(xiàn)中文數(shù)字與阿拉伯數(shù)字的相互轉(zhuǎn)換

    Python使用cn2an實現(xiàn)中文數(shù)字與阿拉伯數(shù)字的相互轉(zhuǎn)換

    這篇文章主要介紹了Python使用cn2an實現(xiàn)中文數(shù)字與阿拉伯數(shù)字的相互轉(zhuǎn)換,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • Python入門之模塊和包用法詳解

    Python入門之模塊和包用法詳解

    這篇文章主要為大家詳細介紹一下Python中的包與模塊的使用,文中的示例講解詳細,對我們學習Python有一定幫助,感興趣的小伙伴可以學習一下
    2022-07-07
  • pyinstaller參數(shù)介紹以及總結(jié)詳解

    pyinstaller參數(shù)介紹以及總結(jié)詳解

    這篇文章主要介紹了pyinstaller參數(shù)介紹以及總結(jié)詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-07-07
  • Python從PDF中提取文本的方法效率總結(jié)

    Python從PDF中提取文本的方法效率總結(jié)

    日常工作中我們經(jīng)常會用到pdf格式的文件,大多數(shù)情況下是瀏覽或者編輯pdf信息,但有時候需要提取pdf中的文本,這篇文章主要給大家總結(jié)介紹了關(guān)于Python從PDF中提取文本的方法效率,需要的朋友可以參考下
    2023-09-09
  • python基于scrapy爬取京東筆記本電腦數(shù)據(jù)并進行簡單處理和分析

    python基于scrapy爬取京東筆記本電腦數(shù)據(jù)并進行簡單處理和分析

    這篇文章主要介紹了python基于scrapy爬取京東筆記本電腦數(shù)據(jù)并進行簡單處理和分析的實例,幫助大家更好的理解和學習使用python。感興趣的朋友可以了解下
    2021-04-04
  • Python time庫的時間時鐘處理

    Python time庫的時間時鐘處理

    這篇文章主要介紹了Python time庫的時間時鐘處理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05
  • 淺談pandas中DataFrame關(guān)于顯示值省略的解決方法

    淺談pandas中DataFrame關(guān)于顯示值省略的解決方法

    下面小編就為大家分享一篇淺談pandas中DataFrame關(guān)于顯示值省略的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04

最新評論

忻州市| 周口市| 陈巴尔虎旗| 正安县| 屯门区| 万源市| 津市市| 茂名市| 怀化市| 瑞安市| 扎兰屯市| 乌拉特前旗| 随州市| 承德市| 比如县| 茶陵县| 蒙阴县| 民县| 五家渠市| 都安| 许昌市| 潼关县| 河源市| 常熟市| 石家庄市| 通山县| 晋州市| 泉州市| 贵州省| 沁水县| 天等县| 林周县| 三明市| 定远县| 洛阳市| 襄樊市| 茂名市| 稻城县| 图木舒克市| 谷城县| 海口市|