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

Python Tkinter實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能

 更新時(shí)間:2018年01月30日 09:11:04   作者:Cullenyy  
這篇文章主要為大家詳細(xì)介紹了Python Tkinter實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

閑暇時(shí)間用tkinter寫了個(gè)簡(jiǎn)易計(jì)算器,可實(shí)現(xiàn)簡(jiǎn)單的加減乘除運(yùn)算,用了Button和Entry2個(gè)控件,下面是代碼,只是簡(jiǎn)單的用了偏函數(shù)partial,因?yàn)槟敲炊郻utton的大部分參數(shù)都是一樣的,使用偏函數(shù)可以簡(jiǎn)化參數(shù)傳遞,避免同樣的參數(shù)傳遞寫N次。

# -*- coding: utf-8 -*- 
#author: Cullen 
 
#import the module 
from Tkinter import * 
import tkFont 
import os 
from functools import partial 
from PIL import Image, ImageTk 
 
def get_input(entry, argu): 
  entry.insert(END, argu) 
 
def backspace(entry): 
  input_len = len(entry.get()) 
  entry.delete(input_len - 1) 
 
def clear(entry): 
  entry.delete(0, END) 
 
def calc(entry): 
  input = entry.get() 
  output = str(eval(input.strip())) 
  clear(entry) 
  entry.insert(END, output) 
 
def cal(): 
  root = Tk() 
  root.title("Calc") 
  root.resizable(0,0) 
 
  entry_font = tkFont.Font(size=12) 
  entry = Entry(root, justify="right", font=entry_font) 
  entry.grid(row=0, column=0, columnspan=4, sticky=N+W+S+E, padx=5, pady=5) 
 
  button_font = tkFont.Font(size=10, weight=tkFont.BOLD) 
  button_bg = '#D5E0EE' 
  button_active_bg = '#E5E35B' 
 
  myButton = partial(Button, root, bg=button_bg, padx=10, pady=3, activebackground = button_active_bg) 
 
  button7 = myButton(text='7', command=lambda : get_input(entry, '7')) 
  button7.grid(row=1, column=0, pady=5) 
 
  button8 = myButton(text='8', command=lambda : get_input(entry, '8')) 
  button8.grid(row=1, column=1, pady=5) 
 
  button9 = myButton(text='9', command=lambda : get_input(entry, '9')) 
  button9.grid(row=1, column=2, pady=5) 
 
  button10 = myButton(text='+', command=lambda : get_input(entry, '+')) 
  button10.grid(row=1, column=3, pady=5) 
 
  button4 = myButton(text='4', command=lambda : get_input(entry, '4')) 
  button4.grid(row=2, column=0, pady=5) 
 
  button5 = myButton(text='5', command=lambda : get_input(entry, '5')) 
  button5.grid(row=2, column=1, pady=5) 
 
  button6 = myButton(text='6', command=lambda : get_input(entry, '6')) 
  button6.grid(row=2, column=2, pady=5) 
 
  button11 = myButton(text='-', command=lambda : get_input(entry, '-')) 
  button11.grid(row=2, column=3, pady=5) 
 
  button1 = myButton(text='1', command=lambda : get_input(entry, '1')) 
  button1.grid(row=3, column=0, pady=5) 
 
  button2 = myButton(text='2', command=lambda : get_input(entry, '2')) 
  button2.grid(row=3, column=1, pady=5) 
 
  button3 = myButton(text='3', command=lambda : get_input(entry, '3')) 
  button3.grid(row=3, column=2, pady=5) 
 
  button12 = myButton(text='*', command=lambda : get_input(entry, '*')) 
  button12.grid(row=3, column=3, pady=5) 
 
  button0 = myButton(text='0', command=lambda : get_input(entry, '0')) 
  button0.grid(row=4, column=0, columnspan=2, padx=3, pady=5, sticky=N+S+E+W) 
 
  button13 = myButton(text='.', command=lambda : get_input(entry, '.')) 
  button13.grid(row=4, column=2, pady=5) 
 
  button14 = Button(root, text='/', bg=button_bg, padx=10, pady=3, 
           command=lambda : get_input(entry, '/')) 
  button14.grid(row=4, column=3, pady=5) 
 
  button15 = Button(root, text='<-', bg=button_bg, padx=10, pady=3, 
           command=lambda : backspace(entry), activebackground = button_active_bg) 
  button15.grid(row=5, column=0, pady=5) 
 
  button16 = Button(root, text='C', bg=button_bg, padx=10, pady=3, 
           command=lambda : clear(entry), activebackground = button_active_bg) 
  button16.grid(row=5, column=1, pady=5) 
 
  button17 = Button(root, text='=', bg=button_bg, padx=10, pady=3, 
           command=lambda : calc(entry), activebackground = button_active_bg) 
  button17.grid(row=5, column=2, columnspan=2, padx=3, pady=5, sticky=N+S+E+W) 
 
  root.mainloop() 
 
if __name__ == '__main__': 
  cal() 

下面是運(yùn)行結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • opencv python截取圓形區(qū)域的實(shí)現(xiàn)

    opencv python截取圓形區(qū)域的實(shí)現(xiàn)

    本文主要介紹了opencv python截取圓形區(qū)域的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Python讀取TIF文件的兩種方法實(shí)現(xiàn)

    Python讀取TIF文件的兩種方法實(shí)現(xiàn)

    本文主要介紹了Python讀取TIF文件的兩種方法實(shí)現(xiàn),包括使用tifffile庫(kù)和Pillow庫(kù)逐幀讀取TIFF文件,具有一定的參考價(jià)值,感興趣的可以了解一下
    2025-01-01
  • python轉(zhuǎn)換字符串為摩爾斯電碼的方法

    python轉(zhuǎn)換字符串為摩爾斯電碼的方法

    這篇文章主要介紹了python轉(zhuǎn)換字符串為摩爾斯電碼的方法,涉及Python字符串及編碼操作的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-07-07
  • Keras框架中的epoch、bacth、batch size、iteration使用介紹

    Keras框架中的epoch、bacth、batch size、iteration使用介紹

    這篇文章主要介紹了Keras框架中的epoch、bacth、batch size、iteration使用介紹,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-06-06
  • Python輕量級(jí)搜索工具Whoosh的使用教程

    Python輕量級(jí)搜索工具Whoosh的使用教程

    本文將為大家簡(jiǎn)單介紹一下Python中的一個(gè)輕量級(jí)搜索工具Whoosh,并給出相應(yīng)的使用示例代碼,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2022-07-07
  • 推薦系統(tǒng)MostPopular算法的Python實(shí)現(xiàn)方式

    推薦系統(tǒng)MostPopular算法的Python實(shí)現(xiàn)方式

    這篇文章主要介紹了推薦系統(tǒng)MostPopular算法的Python實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • 使用IDLE的Python shell窗口實(shí)例詳解

    使用IDLE的Python shell窗口實(shí)例詳解

    在本篇文章里小編給各位整理的是關(guān)于使用IDLE的Python shell窗口實(shí)例詳解內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2019-11-11
  • 詳解Python核心對(duì)象類型字符串

    詳解Python核心對(duì)象類型字符串

    本篇文章通過(guò)理論知識(shí)點(diǎn)給大家講述了Python核心對(duì)象類型字符串的相關(guān)知識(shí)內(nèi)容,對(duì)此有興趣的一起學(xué)習(xí)下。
    2018-02-02
  • python3利用ctypes傳入一個(gè)字符串類型的列表方法

    python3利用ctypes傳入一個(gè)字符串類型的列表方法

    今天小編就為大家分享一篇python3利用ctypes傳入一個(gè)字符串類型的列表方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-02-02
  • pycharm?將python文件打包為exe格式的方法

    pycharm?將python文件打包為exe格式的方法

    今天小編就為大家分享一篇pycharm?將python文件打包為exe格式的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01

最新評(píng)論

珲春市| 临城县| 湘阴县| 望江县| 大方县| 大邑县| 太仓市| 漠河县| 小金县| 双城市| 宁津县| 台安县| 裕民县| 保康县| 霍林郭勒市| 武城县| 囊谦县| 伊金霍洛旗| 泉州市| 大洼县| 黎平县| 吉木乃县| 钦州市| 龙游县| 岗巴县| 稷山县| 安阳县| 宜州市| 二手房| 苗栗县| 来安县| 洛川县| 大关县| 龙江县| 正镶白旗| 土默特左旗| 南澳县| 甘南县| 思南县| 甘肃省| 枣阳市|