亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python簡(jiǎn)易計(jì)算器制作方法代碼詳解

 更新時(shí)間:2019年10月31日 10:31:06   作者:EdisonChenyao  
這篇文章主要介紹了Python簡(jiǎn)易計(jì)算器制作方法,文中代碼主要用到了python中的tkinter庫(kù),代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

主要用到的工具是Python中的Tkinter庫(kù)

比較簡(jiǎn)單

直接上圖形界面和代碼

在這里插入圖片描述

引用Tkinter庫(kù)

from tkinter import *

建立主窗口對(duì)象

window=Tk() #設(shè)置窗口對(duì)象
window.title('counting machine')
window.geometry("350x280")
window['bg']='red'

建立標(biāo)簽框以及標(biāo)簽(將運(yùn)算字符串顯示在上面)

frame=LabelFrame(window,bg='yellow',width=350,height=50)
frame.pack()
frame.place(x=0,y=0)
label=Label(frame,text="1+1=2",height=3,width=50,bg='yellow')
label.pack() #顯示框

設(shè)置全局變量字符串s,按一個(gè)按鈕,將按鈕對(duì)應(yīng)的運(yùn)算符加到這個(gè)字符串s中,最后利用eval函數(shù)進(jìn)行計(jì)算。

global s
s=""

按鈕0-9以及小數(shù)點(diǎn)的實(shí)現(xiàn)(大致思路都是一樣的)

#按鈕.
def figure_dot():
  global s
  s=s+"."
  label.config(text=s)
btn0=Button(window,text=".",width=4,command=figure_dot,bg='yellow')
btn0.place(x=150,y=220) #按鈕.
#按鈕0
def figure_0():
  global s
  s=s+"0"
  label.config(text=s)
btn0=Button(window,text="0",width=4,command=figure_0,bg='yellow')
btn0.place(x=80,y=220) #按鈕0
#按鈕1
def figure_1():
  global s
  s=s+"1"
  label.config(text=s)
btn1=Button(window,text="1",width=4,command=figure_1,bg='yellow')
btn1.place(x=10,y=80) #按鈕1
#按鈕2
def figure_2():
  global s
  s=s+"2"
  label.config(text=s)
btn2=Button(window,text="2",width=4,command=figure_2,bg='yellow')
btn2.place(x=80,y=80)#按鈕2
#按鈕3
def figure_3():
  global s
  s=s+"3"
  label.config(text=s)
btn3=Button(window,text="3",width=4,command=figure_3,bg='yellow')
btn3.place(x=150,y=80)#按鈕3
#按鈕4
def figure_4():
  global s
  s=s+"4"
  label.config(text=s)
btn4=Button(window,text="4",width=4,command=figure_4,bg='yellow')
btn4.place(x=10,y=130)#按鈕4
#按鈕5
def figure_5():
  global s
  s=s+"5"
  label.config(text=s)
btn5=Button(window,text="5",width=4,command=figure_5,bg='yellow')
btn5.place(x=80,y=130)#按鈕5
#按鈕6
def figure_6():
  global s
  s=s+"6"
  label.config(text=s)
btn6=Button(window,text="6",width=4,command=figure_6,bg='yellow')
btn6.place(x=150,y=130)#按鈕6
#按鈕7
def figure_7():
  global s
  s=s+"7"
  label.config(text=s)
btn7=Button(window,text="7",width=4,command=figure_7,bg='yellow')
btn7.place(x=10,y=180)#按鈕7
#按鈕8
def figure_8():
  global s
  s=s+"8"
  label.config(text=s)
btn8=Button(window,text="8",width=4,command=figure_8,bg='yellow')
btn8.place(x=80,y=180)#按鈕8
#按鈕9
def figure_9():
  global s
  s=s+"9"
  label.config(text=s)
btn9=Button(window,text="9",width=4,command=figure_9,bg='yellow')
btn9.place(x=150,y=180)#按鈕9
運(yùn)算符號(hào)的實(shí)現(xiàn)(±*/)

#加法按鈕
def figure_addition():
  global s
  s=s+"+"
  label.config(text=s)
btn_add=Button(window,text="+",width=4,command=figure_addition,bg='yellow')
btn_add.place(x=220,y=80)#加法按鈕
#減法按鈕
def figure_subtraction():
  global s
  s=s+"-"
  label.config(text=s)
btn_sub=Button(window,text="-",width=4,command=figure_subtraction,bg='yellow')
btn_sub.place(x=220,y=130)#減法按鈕
#乘法按鈕
def figure_multiplication():
  global s
  s=s+"*"
  label.config(text=s)
btn_multi=Button(window,text="*",width=4,command=figure_multiplication,bg='yellow')
btn_multi.place(x=290,y=80)#乘法按鈕
#除法按鈕
def figure_division():
  global s
  s=s+"/"
  label.config(text=s)
btn_divi=Button(window,text="/",width=4,command=figure_division,bg='yellow')
btn_divi.place(x=290,y=130)#除法按鈕

清空窗口按鈕的實(shí)現(xiàn)

#清空按鈕
def figure_clear():
  global s
  s=""
  label.config(text=s)
btn_clear=Button(window,text="clear",width=4,command=figure_clear,bg='yellow')
btn_clear.place(x=220,y=180)#清空按鈕

結(jié)果輸出的實(shí)現(xiàn)(eval函數(shù))

#結(jié)果按鈕
def figure_value():
  global s
  x=eval(s)
  s=str(x)
  label.config(text=s)
btn_value=Button(window,text="=",width=4,command=figure_value,bg='yellow')
btn_value.place(x=290,y=180)

顏色變換的實(shí)現(xiàn)(紅變粉)

def figure_colorchange():
  window.config(bg="pink")
btn_value=Button(window,text="color",width=4,command=figure_colorchange,bg='yellow')
btn_value.place(x=10,y=220)#改變顏色
window.mainloop()

變換后

在這里插入圖片描述

這個(gè)簡(jiǎn)易計(jì)算器也就實(shí)現(xiàn)了,當(dāng)然也可以加入其他的功能,如開(kāi)方,乘冪等功能。

總結(jié)

以上所述是小編給大家介紹的Python簡(jiǎn)易計(jì)算器制作方法代碼詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • Python繪制的愛(ài)心樹(shù)與表白代碼(完整代碼)

    Python繪制的愛(ài)心樹(shù)與表白代碼(完整代碼)

    這篇文章主要介紹了Python繪制的愛(ài)心樹(shù)與表白代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • python爬蟲(chóng)爬取筆趣網(wǎng)小說(shuō)網(wǎng)站過(guò)程圖解

    python爬蟲(chóng)爬取筆趣網(wǎng)小說(shuō)網(wǎng)站過(guò)程圖解

    這篇文章主要介紹了python爬蟲(chóng)爬取筆趣網(wǎng)小說(shuō)網(wǎng)站過(guò)程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • 使用Python實(shí)現(xiàn)計(jì)算DICOM圖像兩點(diǎn)真實(shí)距離

    使用Python實(shí)現(xiàn)計(jì)算DICOM圖像兩點(diǎn)真實(shí)距離

    這篇文章主要為大家詳細(xì)介紹了如何使用Python實(shí)現(xiàn)計(jì)算DICOM圖像兩點(diǎn)真實(shí)距離,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-11-11
  • Python裝飾器的兩種使用心得

    Python裝飾器的兩種使用心得

    裝飾器(Decorators)是 Python 的一個(gè)重要部分。簡(jiǎn)單地說(shuō):他們是修改其他函數(shù)的功能的函數(shù)。他們有助于讓我們的代碼更簡(jiǎn)短,也更Pythonic(Python范兒),今天通過(guò)本文給大家分享Python裝飾器使用小結(jié),感興趣的朋友一起看看吧
    2021-09-09
  • Python線程的兩種編程方式

    Python線程的兩種編程方式

    這篇文章主要介紹了Python線程的兩種編程方式,Python中如果要使用線程的話,一種是函數(shù)式,一種是用類來(lái)包裝的線程對(duì)象,需要的朋友可以參考下
    2015-04-04
  • 舉例詳解Python中的split()函數(shù)的使用方法

    舉例詳解Python中的split()函數(shù)的使用方法

    這篇文章主要介紹了舉例詳解Python中的split()函數(shù)的使用方法,split()函數(shù)的使用是Python學(xué)習(xí)當(dāng)中的基礎(chǔ)知識(shí),通常用于將字符串切片并轉(zhuǎn)換為列表,需要的朋友可以參考下
    2015-04-04
  • 基于深度學(xué)習(xí)和OpenCV實(shí)現(xiàn)目標(biāo)檢測(cè)

    基于深度學(xué)習(xí)和OpenCV實(shí)現(xiàn)目標(biāo)檢測(cè)

    這篇文章主要介紹了通過(guò)使用OpenCV進(jìn)行基于深度學(xué)習(xí)的對(duì)象檢測(cè)以及使用OpenCV檢測(cè)視頻,文中的示例代碼講解詳細(xì),需要的可以參考一下
    2021-12-12
  • python3+PyQt5實(shí)現(xiàn)使用剪貼板做復(fù)制與粘帖示例

    python3+PyQt5實(shí)現(xiàn)使用剪貼板做復(fù)制與粘帖示例

    本篇文章主要介紹了python3+PyQt5實(shí)現(xiàn)使用剪貼板做復(fù)制與粘帖示例,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-01-01
  • 用python實(shí)現(xiàn)海龜賽跑小游戲

    用python實(shí)現(xiàn)海龜賽跑小游戲

    大家好,本篇文章主要講的是用python實(shí)現(xiàn)海龜賽跑小游戲,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-01-01
  • Django中的用戶身份驗(yàn)證示例詳解

    Django中的用戶身份驗(yàn)證示例詳解

    這篇文章主要給大家介紹了關(guān)于Django中用戶身份驗(yàn)證的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用SQL Django具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08

最新評(píng)論