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

使用Python寫(xiě)一個(gè)標(biāo)準(zhǔn)版和程序員版計(jì)算器

 更新時(shí)間:2025年12月03日 09:41:48   作者:熊貓_豆豆  
Python是一種廣泛使用的高級(jí)編程語(yǔ)言,以其易讀性、簡(jiǎn)潔性和豐富的庫(kù)支持而聞名,這篇文章主要介紹了使用Python寫(xiě)一個(gè)標(biāo)準(zhǔn)版和程序員版計(jì)算器的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下

前言

本文介紹了一個(gè)基于Tkinter的多功能計(jì)算器實(shí)現(xiàn)。該計(jì)算器支持標(biāo)準(zhǔn)模式和程序員模式:標(biāo)準(zhǔn)模式提供基本運(yùn)算、三角函數(shù)、對(duì)數(shù)等數(shù)學(xué)函數(shù);程序員模式支持二進(jìn)制/八進(jìn)制/十六進(jìn)制運(yùn)算及位操作。程序采用了面向?qū)ο笤O(shè)計(jì),通過(guò)Calculator類實(shí)現(xiàn)核心功能,包括進(jìn)制轉(zhuǎn)換、表達(dá)式驗(yàn)證、錯(cuò)誤處理等。計(jì)算器界面包含多進(jìn)制實(shí)時(shí)顯示區(qū)域、主顯示屏和動(dòng)態(tài)切換的按鈕面板,針對(duì)不同模式提供相應(yīng)的計(jì)算功能。特別優(yōu)化了負(fù)號(hào)處理、表達(dá)式驗(yàn)證和進(jìn)制轉(zhuǎn)換邏輯,確保計(jì)算準(zhǔn)確性和用戶體驗(yàn)。

效果圖

完整示例代碼 

import tkinter as tk
from tkinter import ttk, messagebox
import math
import re

class Calculator:
    def __init__(self, root):
        self.root = root
        self.root.title("多功能計(jì)算器")
        self.root.geometry("700x750")
        self.root.resizable(False, False)
        
        # 初始化變量
        self.mode = "standard"
        self.current_expression = ""
        self.current_base = 10  # 默認(rèn)十進(jìn)制
        self.create_widgets()
        
    def create_widgets(self):
        # 多進(jìn)制顯示區(qū)域 - 移到最上方,按列排列
        self.base_display_frame = ttk.Frame(self.root)
        self.base_display_frame.pack(fill=tk.X, padx=10, pady=5)
        
        # 二進(jìn)制顯示 - 第一列
        bin_frame = ttk.Frame(self.base_display_frame)
        bin_frame.grid(row=0, column=0, sticky=tk.W, padx=5, pady=2)
        ttk.Label(bin_frame, text="二進(jìn)制 (Bin):").pack(anchor=tk.W)
        self.bin_var = tk.StringVar()
        ttk.Entry(bin_frame, textvariable=self.bin_var, state="readonly", width=30).pack(fill=tk.X)
        
        # 八進(jìn)制顯示 - 第二列
        oct_frame = ttk.Frame(self.base_display_frame)
        oct_frame.grid(row=0, column=1, sticky=tk.W, padx=5, pady=2)
        ttk.Label(oct_frame, text="八進(jìn)制 (Oct):").pack(anchor=tk.W)
        self.oct_var = tk.StringVar()
        ttk.Entry(oct_frame, textvariable=self.oct_var, state="readonly", width=20).pack(fill=tk.X)
        
        # 十進(jìn)制顯示 - 第三列
        dec_frame = ttk.Frame(self.base_display_frame)
        dec_frame.grid(row=0, column=2, sticky=tk.W, padx=5, pady=2)
        ttk.Label(dec_frame, text="十進(jìn)制 (Dec):").pack(anchor=tk.W)
        self.dec_var = tk.StringVar()
        ttk.Entry(dec_frame, textvariable=self.dec_var, state="readonly", width=20).pack(fill=tk.X)
        
        # 十六進(jìn)制顯示 - 第四列
        hex_frame = ttk.Frame(self.base_display_frame)
        hex_frame.grid(row=0, column=3, sticky=tk.W, padx=5, pady=2)
        ttk.Label(hex_frame, text="十六進(jìn)制 (Hex):").pack(anchor=tk.W)
        self.hex_var = tk.StringVar()
        ttk.Entry(hex_frame, textvariable=self.hex_var, state="readonly", width=20).pack(fill=tk.X)
        
        # 模式切換框架
        mode_frame = ttk.Frame(self.root)
        mode_frame.pack(fill=tk.X, padx=5, pady=5)
        
        ttk.Button(mode_frame, text="標(biāo)準(zhǔn)版", command=self.switch_to_standard).pack(side=tk.LEFT, padx=5)
        ttk.Button(mode_frame, text="程序員版", command=self.switch_to_programmer).pack(side=tk.LEFT, padx=5)
        
        # 主顯示框
        self.display_var = tk.StringVar()
        self.display = ttk.Entry(self.root, textvariable=self.display_var, font=('Arial', 24), justify=tk.RIGHT)
        self.display.pack(fill=tk.X, padx=10, pady=10)
        self.display.config(state='readonly')
        
        # 按鈕框架
        self.buttons_frame = ttk.Frame(self.root)
        self.buttons_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
        
        # 初始顯示標(biāo)準(zhǔn)版
        self.create_standard_buttons()
    
    def switch_to_standard(self):
        self.mode = "standard"
        # 清空現(xiàn)有按鈕
        for widget in self.buttons_frame.winfo_children():
            widget.destroy()
        self.create_standard_buttons()
        self.clear_display()
    
    def switch_to_programmer(self):
        self.mode = "programmer"
        # 清空現(xiàn)有按鈕
        for widget in self.buttons_frame.winfo_children():
            widget.destroy()
        self.create_programmer_buttons()
        self.clear_display()
    
    def create_standard_buttons(self):
        # 按鈕布局
        buttons = [
            ('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3), ('C', 1, 4),
            ('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3), ('?', 2, 4),
            ('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3), ('±', 3, 4),
            ('0', 4, 0), ('.', 4, 1), ('=', 4, 2), ('+', 4, 3), ('^', 4, 4),
            ('sin', 5, 0), ('cos', 5, 1), ('tan', 5, 2), ('log', 5, 3), ('√', 5, 4),
            ('π', 6, 0), ('e', 6, 1), ('exp', 6, 2), ('ln', 6, 3), ('!', 6, 4)
        ]
        
        # 設(shè)置網(wǎng)格權(quán)重
        for i in range(7):
            self.buttons_frame.grid_rowconfigure(i, weight=1)
        for i in range(5):
            self.buttons_frame.grid_columnconfigure(i, weight=1)
        
        # 創(chuàng)建按鈕
        for text, row, col in buttons:
            btn = ttk.Button(self.buttons_frame, text=text, command=lambda t=text: self.on_button_click(t))
            btn.grid(row=row, column=col, padx=5, pady=5, sticky="nsew")
    
    def create_programmer_buttons(self):
        # 進(jìn)制選擇
        base_frame = ttk.Frame(self.buttons_frame)
        base_frame.grid(row=0, column=0, columnspan=5, sticky="nsew", padx=5, pady=5)
        
        ttk.Button(base_frame, text="二進(jìn)制", command=lambda: self.set_base(2)).pack(side=tk.LEFT, padx=2, expand=True, fill=tk.X)
        ttk.Button(base_frame, text="八進(jìn)制", command=lambda: self.set_base(8)).pack(side=tk.LEFT, padx=2, expand=True, fill=tk.X)
        ttk.Button(base_frame, text="十進(jìn)制", command=lambda: self.set_base(10)).pack(side=tk.LEFT, padx=2, expand=True, fill=tk.X)
        ttk.Button(base_frame, text="十六進(jìn)制", command=lambda: self.set_base(16)).pack(side=tk.LEFT, padx=2, expand=True, fill=tk.X)
        
        # 程序員版按鈕布局(修復(fù)空按鈕問(wèn)題,替換為空文本按鈕為退格)
        buttons = [
            ('A', 1, 0), ('B', 1, 1), ('C', 1, 2), ('D', 1, 3), ('E', 1, 4),
            ('F', 2, 0), ('7', 2, 1), ('8', 2, 2), ('9', 2, 3), ('/', 2, 4),
            ('4', 3, 0), ('5', 3, 1), ('6', 3, 2), ('*', 3, 3), ('%', 3, 4),
            ('1', 4, 0), ('2', 4, 1), ('3', 4, 2), ('-', 4, 3), ('<<', 4, 4),
            ('0', 5, 0), ('?', 5, 1), ('=', 5, 2), ('+', 5, 3), ('>>', 5, 4),
            ('&', 6, 0), ('|', 6, 1), ('^', 6, 2), ('~', 6, 3), ('C', 6, 4)
        ]
        
        # 設(shè)置網(wǎng)格權(quán)重
        for i in range(7):
            self.buttons_frame.grid_rowconfigure(i, weight=1)
        for i in range(5):
            self.buttons_frame.grid_columnconfigure(i, weight=1)
        
        # 創(chuàng)建按鈕
        for text, row, col in buttons:
            btn = ttk.Button(self.buttons_frame, text=text, command=lambda t=text: self.on_button_click(t))
            btn.grid(row=row, column=col, padx=5, pady=5, sticky="nsew")
    
    def set_base(self, base):
        """切換當(dāng)前進(jìn)制,并轉(zhuǎn)換現(xiàn)有表達(dá)式(修復(fù)進(jìn)制轉(zhuǎn)換邏輯)"""
        if self.current_expression:
            try:
                # 先將當(dāng)前表達(dá)式按原進(jìn)制解析為十進(jìn)制(處理負(fù)號(hào))
                if self.current_expression.startswith('-'):
                    decimal_val = -int(self.current_expression[1:], self.current_base)
                else:
                    decimal_val = int(self.current_expression, self.current_base)
                # 再轉(zhuǎn)換為新進(jìn)制字符串(負(fù)號(hào)單獨(dú)處理)
                if decimal_val < 0:
                    self.current_expression = '-' + self.convert_base(-decimal_val, base)
                else:
                    self.current_expression = self.convert_base(decimal_val, base)
                self.display_var.set(self.current_expression)
            except ValueError:
                messagebox.showerror("進(jìn)制錯(cuò)誤", "當(dāng)前表達(dá)式包含無(wú)效字符,無(wú)法轉(zhuǎn)換")
                self.clear_display()
        # 更新當(dāng)前進(jìn)制
        self.current_base = base
        # 刷新多進(jìn)制顯示
        self.update_base_display()
    
    def on_button_click(self, text):
        """統(tǒng)一按鈕點(diǎn)擊處理(修復(fù)位運(yùn)算按鈕邏輯)"""
        if text == '=':
            self.calculate()
        elif text == 'C':
            self.clear_display()
        elif text == '?':
            self.backspace()
        elif text == '±':
            self.toggle_sign()
        elif text in ['sin', 'cos', 'tan', 'log', 'ln', '√', 'exp', '!']:
            self.function_operation(text)
        elif text in ['π', 'e']:
            self.constant_operation(text)
        else:
            # 所有輸入(數(shù)字、運(yùn)算符)統(tǒng)一走表達(dá)式拼接
            self.append_to_expression(text)
    
    def append_to_expression(self, text):
        """拼接表達(dá)式,增加嚴(yán)格合法性校驗(yàn)(修復(fù)連續(xù)運(yùn)算符問(wèn)題)"""
        # 1. 程序員模式輸入校驗(yàn)
        if self.mode == "programmer":
            # 非十六進(jìn)制不允許輸入A-F
            if self.current_base != 16 and text in ['A', 'B', 'C', 'D', 'E', 'F']:
                messagebox.showwarning("輸入錯(cuò)誤", f"{self.current_base}進(jìn)制僅支持0-{self.current_base-1}")
                return
            # 二進(jìn)制只允許0、1和運(yùn)算符
            if self.current_base == 2 and text not in ['0', '1', '+', '-', '*', '/', '&', '|', '^', '~', '<<', '>>', '%']:
                messagebox.showwarning("輸入錯(cuò)誤", "二進(jìn)制僅支持輸入0、1和運(yùn)算符")
                return
        
        # 2. 避免開(kāi)頭為無(wú)效運(yùn)算符(除負(fù)號(hào))
        if not self.current_expression:
            if text in ['+', '*', '/', '^', '&', '|', '<<', '>>', '%']:
                messagebox.showwarning("輸入錯(cuò)誤", "表達(dá)式不能以運(yùn)算符開(kāi)頭")
                return
        
        # 3. 避免連續(xù)運(yùn)算符(修復(fù)運(yùn)算符疊加問(wèn)題)
        if self.current_expression:
            last_char = self.current_expression[-1]
            # 檢測(cè)上一個(gè)字符是否為運(yùn)算符(含雙字符運(yùn)算符<<、>>)
            is_last_op = (last_char in ['+', '-', '*', '/', '^', '&', '|', '%']) or \
                         (len(self.current_expression)>=2 and self.current_expression[-2:] in ['<<', '>>'])
            # 檢測(cè)當(dāng)前輸入是否為運(yùn)算符
            is_current_op = (text in ['+', '-', '*', '/', '^', '&', '|', '%']) or (text in ['<<', '>>'])
            
            if is_last_op and is_current_op:
                messagebox.showwarning("輸入錯(cuò)誤", "不允許連續(xù)輸入運(yùn)算符")
                return
        
        # 4. 拼接表達(dá)式并更新顯示
        self.current_expression += str(text)
        self.display_var.set(self.current_expression)
        self.update_base_display()
    
    def clear_display(self):
        """清空表達(dá)式和所有顯示"""
        self.current_expression = ""
        self.display_var.set("")
        self.update_base_display()
    
    def backspace(self):
        """退格刪除最后一個(gè)字符(修復(fù)多字符運(yùn)算符刪除)"""
        if self.current_expression:
            # 處理雙字符運(yùn)算符(<<、>>)
            if len(self.current_expression)>=2 and self.current_expression[-2:] in ['<<', '>>']:
                self.current_expression = self.current_expression[:-2]
            else:
                self.current_expression = self.current_expression[:-1]
            self.display_var.set(self.current_expression)
            self.update_base_display()
    
    def toggle_sign(self):
        """切換正負(fù)號(hào)(修復(fù)負(fù)號(hào)位置錯(cuò)誤)"""
        if not self.current_expression:
            self.current_expression = '-'
        elif self.current_expression == '-':
            self.current_expression = ""
        elif self.current_expression.startswith('-'):
            self.current_expression = self.current_expression[1:]
        else:
            # 僅在表達(dá)式開(kāi)頭添加負(fù)號(hào)(避免中間加負(fù)號(hào))
            self.current_expression = '-' + self.current_expression
        self.display_var.set(self.current_expression)
        self.update_base_display()
    
    def function_operation(self, func):
        """處理數(shù)學(xué)函數(shù)運(yùn)算(修復(fù)函數(shù)計(jì)算邏輯)"""
        try:
            if not self.current_expression:
                raise ValueError("請(qǐng)先輸入運(yùn)算數(shù)值")
            
            # 解析當(dāng)前表達(dá)式為數(shù)值(支持小數(shù))
            value = float(self.current_expression)
            result = 0
            
            # 函數(shù)計(jì)算(確保數(shù)學(xué)正確性)
            if func == 'sin':
                result = math.sin(math.radians(value))  # 角度轉(zhuǎn)弧度(符合日常使用習(xí)慣)
            elif func == 'cos':
                result = math.cos(math.radians(value))
            elif func == 'tan':
                result = math.tan(math.radians(value))
            elif func == 'log':
                if value <= 0:
                    raise ValueError("對(duì)數(shù)參數(shù)必須大于0")
                result = math.log10(value)
            elif func == 'ln':
                if value <= 0:
                    raise ValueError("自然對(duì)數(shù)參數(shù)必須大于0")
                result = math.log(value)
            elif func == '√':
                if value < 0:
                    raise ValueError("平方根參數(shù)不能為負(fù)數(shù)")
                result = math.sqrt(value)
            elif func == 'exp':
                result = math.exp(value)  # 計(jì)算 e^value
            elif func == '!':
                if value < 0 or not value.is_integer():
                    raise ValueError("階乘僅支持非負(fù)整數(shù)")
                result = math.factorial(int(value))
            
            # 處理結(jié)果顯示(移除末尾多余的0和小數(shù)點(diǎn))
            self.current_expression = str(round(result, 10))
            if '.' in self.current_expression:
                self.current_expression = self.current_expression.rstrip('0').rstrip('.')
            self.display_var.set(self.current_expression)
            self.update_base_display()
            
        except Exception as e:
            messagebox.showerror("函數(shù)錯(cuò)誤", str(e))
            self.clear_display()
    
    def constant_operation(self, const):
        """插入數(shù)學(xué)常數(shù)(修復(fù)常數(shù)顯示格式)"""
        if const == 'π':
            self.current_expression = str(round(math.pi, 10))
        elif const == 'e':
            self.current_expression = str(round(math.e, 10))
        
        # 清理顯示格式(如 3.1415926536 而非 3.141592653589793)
        if '.' in self.current_expression:
            self.current_expression = self.current_expression.rstrip('0').rstrip('.')
        self.display_var.set(self.current_expression)
        self.update_base_display()
    
    def calculate(self):
        """核心計(jì)算邏輯(區(qū)分標(biāo)準(zhǔn)版/程序員版,修復(fù)表達(dá)式解析錯(cuò)誤)"""
        try:
            if not self.current_expression:
                raise ValueError("請(qǐng)先輸入運(yùn)算表達(dá)式")
            
            result = 0
            if self.mode == "standard":
                # 標(biāo)準(zhǔn)版:支持小數(shù)、冪運(yùn)算和數(shù)學(xué)函數(shù),處理角度轉(zhuǎn)弧度
                expr = self.current_expression.replace('^', '**')  # 冪運(yùn)算轉(zhuǎn)為Python語(yǔ)法
                
                # 定義安全的數(shù)學(xué)函數(shù)環(huán)境(確保sin/cos等使用角度計(jì)算,符合日常習(xí)慣)
                def safe_sin(x):
                    return math.sin(math.radians(x))  # 角度→弧度
                def safe_cos(x):
                    return math.cos(math.radians(x))
                def safe_tan(x):
                    return math.tan(math.radians(x))
                
                # 安全執(zhí)行表達(dá)式(僅暴露必要函數(shù),禁止危險(xiǎn)操作)
                result = eval(
                    expr,
                    {"__builtins__": None},  # 禁用所有內(nèi)置函數(shù)
                    {
                        "sin": safe_sin,
                        "cos": safe_cos,
                        "tan": safe_tan,
                        "log10": math.log10,
                        "log": math.log,
                        "sqrt": math.sqrt,
                        "exp": math.exp,
                        "factorial": math.factorial,
                        "pi": math.pi,
                        "e": math.e
                    }
                )
                
                # 處理結(jié)果顯示格式(移除末尾多余的0和小數(shù)點(diǎn))
                self.current_expression = str(round(result, 10))
                if '.' in self.current_expression:
                    self.current_expression = self.current_expression.rstrip('0').rstrip('.')
            
            else:
                # 程序員版:僅整數(shù)運(yùn)算,先按當(dāng)前進(jìn)制解析為十進(jìn)制計(jì)算
                expr = self.current_expression
                # 1. 處理取反運(yùn)算符~(Python中~x = -x-1,需單獨(dú)處理負(fù)號(hào))
                expr = expr.replace('~', '-~')  # 修復(fù)取反邏輯:~5 → -~5 = -6(符合二進(jìn)制取反)
                
                # 2. 正則匹配表達(dá)式中的數(shù)字(含負(fù)號(hào),如-1A、-10),轉(zhuǎn)為十進(jìn)制
                def parse_num(match):
                    num_str = match.group()
                    # 分離負(fù)號(hào)和數(shù)字本體
                    sign = -1 if num_str.startswith('-') else 1
                    pure_num = num_str.lstrip('-')
                    
                    # 按當(dāng)前進(jìn)制解析數(shù)字
                    try:
                        return str(sign * int(pure_num, self.current_base))
                    except ValueError:
                        raise ValueError(f"無(wú)效{self.current_base}進(jìn)制數(shù)字:{num_str}")
                
                # 匹配規(guī)則:負(fù)號(hào)(可選)+ 數(shù)字/字母(0-9A-F),避免匹配運(yùn)算符
                expr_dec = re.sub(r'-?[0-9A-Fa-f]+', parse_num, expr)
                
                # 3. 執(zhí)行十進(jìn)制運(yùn)算(位運(yùn)算、算術(shù)運(yùn)算)
                result = eval(
                    expr_dec,
                    {"__builtins__": None},
                    {}  # 程序員模式無(wú)需額外函數(shù)
                )
                
                # 4. 結(jié)果轉(zhuǎn)為當(dāng)前進(jìn)制(處理負(fù)號(hào):負(fù)號(hào)單獨(dú)顯示,數(shù)字部分轉(zhuǎn)正)
                if result < 0:
                    self.current_expression = '-' + self.convert_base(-result, self.current_base)
                else:
                    self.current_expression = self.convert_base(result, self.current_base)
            
            # 更新主顯示和多進(jìn)制顯示
            self.display_var.set(self.current_expression)
            self.update_base_display()
            
        except ValueError as ve:
            messagebox.showerror("計(jì)算錯(cuò)誤", str(ve))
            self.clear_display()
        except ZeroDivisionError:
            messagebox.showerror("計(jì)算錯(cuò)誤", "除數(shù)不能為0")
            self.clear_display()
        except Exception as e:
            messagebox.showerror("計(jì)算錯(cuò)誤", f"表達(dá)式格式無(wú)效:{str(e)}")
            self.clear_display()
    
    def convert_base(self, num, base):
        """完整實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)目標(biāo)進(jìn)制(支持2/8/10/16,處理0的特殊情況)"""
        if num == 0:
            return "0"  # 避免0轉(zhuǎn)換后為空
        
        digits = "0123456789ABCDEF"
        result_str = ""
        
        while num > 0:
            remainder = num % base
            result_str = digits[remainder] + result_str  # 余數(shù)逆序拼接
            num = num // base
        
        return result_str
    
    def update_base_display(self):
        """修復(fù)多進(jìn)制顯示邏輯(確保實(shí)時(shí)同步當(dāng)前表達(dá)式的各進(jìn)制值)"""
        if not self.current_expression:
            self.bin_var.set("")
            self.oct_var.set("")
            self.dec_var.set("")
            self.hex_var.set("")
            return
        
        try:
            # 1. 解析當(dāng)前表達(dá)式為十進(jìn)制(區(qū)分標(biāo)準(zhǔn)版和程序員版)
            if self.mode == "standard":
                # 標(biāo)準(zhǔn)版可能含小數(shù),先轉(zhuǎn)為float再取整(多進(jìn)制顯示僅支持整數(shù))
                decimal_val = int(float(self.current_expression))
            else:
                # 程序員版按當(dāng)前進(jìn)制解析
                if self.current_expression.startswith('-'):
                    decimal_val = -int(self.current_expression[1:], self.current_base)
                else:
                    decimal_val = int(self.current_expression, self.current_base)
            
            # 2. 轉(zhuǎn)換為各進(jìn)制并更新顯示
            self.bin_var.set(self.convert_base(abs(decimal_val), 2) if decimal_val !=0 else "0")
            self.oct_var.set(self.convert_base(abs(decimal_val), 8) if decimal_val !=0 else "0")
            self.dec_var.set(str(decimal_val))
            self.hex_var.set(self.convert_base(abs(decimal_val), 16) if decimal_val !=0 else "0")
            
            # 3. 負(fù)號(hào)標(biāo)注(在各進(jìn)制前添加負(fù)號(hào))
            if decimal_val < 0:
                self.bin_var.set("-" + self.bin_var.get())
                self.oct_var.set("-" + self.oct_var.get())
                self.hex_var.set("-" + self.hex_var.get())
        
        except:
            # 表達(dá)式無(wú)效時(shí)清空多進(jìn)制顯示
            self.bin_var.set("(無(wú)效表達(dá)式)")
            self.oct_var.set("(無(wú)效表達(dá)式)")
            self.dec_var.set("(無(wú)效表達(dá)式)")
            self.hex_var.set("(無(wú)效表達(dá)式)")

def main():
    root = tk.Tk()
    app = Calculator(root)
    root.mainloop()

if __name__ == "__main__":
    main()

總結(jié) 

到此這篇關(guān)于使用Python寫(xiě)一個(gè)標(biāo)準(zhǔn)版和程序員版計(jì)算器的文章就介紹到這了,更多相關(guān)Python標(biāo)準(zhǔn)版和程序員版計(jì)算器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python刪除文件夾下相同文件和無(wú)法打開(kāi)的圖片

    python刪除文件夾下相同文件和無(wú)法打開(kāi)的圖片

    這篇文章主要為大家詳細(xì)介紹了python刪除文件夾下相同文件和無(wú)法打開(kāi)的圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Python練習(xí)-承壓計(jì)算

    Python練習(xí)-承壓計(jì)算

    這篇文章主要介紹了Python練習(xí)-承壓計(jì)算,前面我們練習(xí)了Python購(gòu)物單,這篇我們繼續(xù)練習(xí)承壓計(jì)算,和前篇文章一樣還是問(wèn)題描述開(kāi)始,需要的小伙伴可以參考一下
    2022-01-01
  • 查看python安裝路徑及pip安裝的包列表及路徑

    查看python安裝路徑及pip安裝的包列表及路徑

    這篇文章主要介紹了查看python安裝路徑及pip安裝的包列表及路徑,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-04-04
  • Python探索之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的HTTP服務(wù)器

    Python探索之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的HTTP服務(wù)器

    這篇文章主要介紹了Python探索之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的HTTP服務(wù)器,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-10-10
  • 利用pycharm調(diào)試ssh遠(yuǎn)程程序并實(shí)時(shí)同步文件的操作方法

    利用pycharm調(diào)試ssh遠(yuǎn)程程序并實(shí)時(shí)同步文件的操作方法

    這篇文章主要介紹了利用pycharm調(diào)試ssh遠(yuǎn)程程序并實(shí)時(shí)同步文件的操作方法,本篇文章提供了利用pycharm遠(yuǎn)程調(diào)試程序的方法,且使用的編譯器可以是服務(wù)器中的虛擬環(huán)境的編譯器,可以實(shí)時(shí)同步本地與服務(wù)器的文件內(nèi)容,需要的朋友可以參考下
    2022-11-11
  • python使用cartopy在地圖中添加經(jīng)緯線的示例代碼

    python使用cartopy在地圖中添加經(jīng)緯線的示例代碼

    gridlines可以根據(jù)坐標(biāo)系,自動(dòng)繪制網(wǎng)格線,這對(duì)于普通繪圖來(lái)說(shuō)顯然不必單獨(dú)拿出來(lái)說(shuō)說(shuō),但在地圖中,經(jīng)緯線幾乎是必不可少的,本文將給大家介紹了python使用cartopy在地圖中添加經(jīng)緯線的方法,需要的朋友可以參考下
    2024-01-01
  • 用python實(shí)現(xiàn)將數(shù)組元素按從小到大的順序排列方法

    用python實(shí)現(xiàn)將數(shù)組元素按從小到大的順序排列方法

    今天小編就為大家分享一篇用python實(shí)現(xiàn)將數(shù)組元素按從小到大的順序排列方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • 對(duì)python插入數(shù)據(jù)庫(kù)和生成插入sql的示例講解

    對(duì)python插入數(shù)據(jù)庫(kù)和生成插入sql的示例講解

    今天小編就為大家分享一篇對(duì)python插入數(shù)據(jù)庫(kù)和生成插入sql的示例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Python?tuple方法和string常量介紹

    Python?tuple方法和string常量介紹

    這篇文章主要介紹了Python?tuple方法和string常量,文章基于python的相關(guān)資料展開(kāi)詳細(xì)內(nèi)容,對(duì)初學(xué)python的通知有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • 使用Python的pencolor函數(shù)實(shí)現(xiàn)漸變色功能

    使用Python的pencolor函數(shù)實(shí)現(xiàn)漸變色功能

    這篇文章主要介紹了使用Python的pencolor函數(shù)實(shí)現(xiàn)漸變色功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03

最新評(píng)論

章丘市| 吉林省| 中山市| 马龙县| 平凉市| 营山县| 新兴县| 永新县| 西城区| 项城市| 邢台市| 马尔康县| 甘南县| 西安市| 沙洋县| 兴化市| 绍兴县| 新津县| 浮山县| 新乐市| 涟水县| 商都县| 肃宁县| 凌源市| 顺平县| 巴马| 醴陵市| 新邵县| 杨浦区| 秀山| 太湖县| 彰化市| 沐川县| 海淀区| 新沂市| 新龙县| 磐石市| 临安市| 西林县| 浙江省| 和田市|