Aquí el ejemplo de calculadora científica:
`cientifica.py`
```py
from tkinter import *
import math
import tkinter.messagebox
  
root = Tk()
root.title("Scientific Calculator")
root.configure(background="white")
root.resizable(width=False, height=False)
root.geometry("480x568+450+90")
calc = Frame(root)
calc.grid()

class Calc():
    def __init__(self):
        self.total = 0
        self.current = ""
        self.input_value = True
        self.check_sum = False
        self.op = ""
        self.result = False
  
    def number_enter(self, num):
        self.result = False
        firstnum = txtDisplay.get()
        secondnum = str(num)
        if self.input_value:
            self.current = secondnum
            self.input_value = False
        else:
            if secondnum == ".":
                if secondnum in firstnum:
                    return
            self.current = firstnum + secondnum
        self.display(self.current)
  
    def sum_of_total(self):
        self.result = True
        self.current = float(self.current)
        if self.check_sum == True:
            self.valid_function()
        else:
            self.total = float(txtDisplay.get())
  
    def display(self, value):
        txtDisplay.delete(0, END)
        txtDisplay.insert(0, value)
  
    def valid_function(self):
        if self.op == "add":
            self.total += self.current
        if self.op == "sub":
            self.total -= self.current
        if self.op == "multi":
            self.total *= self.current
        if self.op == "divide":
            self.total /= self.current
        if self.op == "mod":
            self.total %= self.current
        self.input_value = True
        self.check_sum = False
        self.display(self.total)
  
    def operation(self, op):
        self.current = float(self.current)
        if self.check_sum:
            self.valid_function()
        elif not self.result:
            self.total = self.current
            self.input_value = True
        self.check_sum = True
        self.op = op
        self.result = False
  
    def clear_entry(self):
        self.result = False
        self.current = "0"
        self.display(0)
        self.input_value = True
  
    def all_clear_entry(self):
        self.clear_entry()
        self.total = 0
  
    def pi(self):
        self.result = False
        self.current = math.pi
        self.display(self.current)
  
    def tau(self):
        self.result = False
        self.current = math.tau
        self.display(self.current)
  
    def e(self):
        self.result = False
        self.current = math.e
        self.display(self.current)
  
    def mathPM(self):
        self.result = False
        self.current = -(float(txtDisplay.get()))
        self.display(self.current)
  
    def squared(self):
        self.result = False
        self.current = math.sqrt(float(txtDisplay.get()))
        self.display(self.current)
  
    def cos(self):
        self.result = False
        self.current = math.cos(math.radians(float(txtDisplay.get())))
        self.display(self.current)
  
    def cosh(self):
        self.result = False
        self.current = math.cosh(math.radians(float(txtDisplay.get())))
        self.display(self.current)
  
    def tan(self):
        self.result = False
        self.current = math.tan(math.radians(float(txtDisplay.get())))
        self.display(self.current)
  
    def tanh(self):
        self.result = False
        self.current = math.tanh(math.radians(float(txtDisplay.get())))
        self.display(self.current)
  
    def sin(self):
        self.result = False
        self.current = math.sin(math.radians(float(txtDisplay.get())))
        self.display(self.current)
  
    def sinh(self):
        self.result = False
        self.current = math.sinh(math.radians(float(txtDisplay.get())))
        self.display(self.current)
  
    def log(self):
        self.result = False
        self.current = math.log(float(txtDisplay.get()))
        self.display(self.current)
  
    def exp(self):
        self.result = False
        self.current = math.exp(float(txtDisplay.get()))
        self.display(self.current)
  
    def acosh(self):
        self.result = False
        self.current = math.acosh(float(txtDisplay.get()))
        self.display(self.current)
  
    def asinh(self):
        self.result = False
        self.current = math.asinh(float(txtDisplay.get()))
        self.display(self.current)
  
    def expm1(self):
        self.result = False
        self.current = math.expm1(float(txtDisplay.get()))
        self.display(self.current)
  
    def lgamma(self):
        self.result = False
        self.current = math.lgamma(float(txtDisplay.get()))
        self.display(self.current)
  
    def degrees(self):
        self.result = False
        self.current = math.degrees(float(txtDisplay.get()))
        self.display(self.current)
  
    def log2(self):
        self.result = False
        self.current = math.log2(float(txtDisplay.get()))
        self.display(self.current)
  
    def log10(self):
        self.result = False
        self.current = math.log10(float(txtDisplay.get()))
        self.display(self.current)
  
    def log1p(self):
        self.result = False
        self.current = math.log1p(float(txtDisplay.get()))
        self.display(self.current)

added_value = Calc()
  
txtDisplay = Entry(calc, font=("Helvetica", 20, "bold"), bg="black", fg="white", bd=30, width=28, justify=RIGHT)
txtDisplay.grid(row=0, column=0, columnspan=4, pady=1)
txtDisplay.insert(0, "0")
  
numberpad = "789456123"
i = 0
btn = []
for j in range(2, 5):
    for k in range(3):
        btn.append(Button(calc, width=6, height=2, bg="black", fg="white", font=("Helvetica", 20, "bold"), bd=4, text=numberpad[i]))
        btn[i].grid(row=j, column=k, pady=1)
        btn[i]["command"] = lambda x = numberpad[i]: added_value.number_enter(x)
        i += 1

btnClear = Button(calc, text=chr(67), width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=added_value.clear_entry).grid(row=1, column=0, pady=1)
btnAllClear = Button(calc, text=chr(67) + chr(69), width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=added_value.all_clear_entry).grid(row=1, column=1, pady=1)
btnsq = Button(calc, text="\u221A", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=added_value.squared).grid(row=1, column=2, pady=1)
btnAdd = Button(calc, text="+", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.operation("add")).grid(row=1, column=3, pady=1)
btnSub = Button(calc, text="-", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.operation("sub")).grid(row=2, column=3, pady=1)
btnMul = Button(calc, text="x", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.operation("multi")).grid(row=3, column=3, pady=1)
btnDiv = Button(calc, text="/", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.operation("divide")).grid(row=4, column=3, pady=1)
btnZero = Button(calc, text="0", width=6, height=2, bg="black", fg="white", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.number_enter(0)).grid(row=5, column=0, pady=1)
btnDot = Button(calc, text=".", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.number_enter(".")).grid(row=5, column=1, pady=1)
btnPM = Button(calc, text=chr(177), width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=added_value.mathPM).grid(row=5, column=2, pady=1)
btnEquals = Button(calc, text="=", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=added_value.sum_of_total).grid(row=5, column=3, pady=1)
# ...
```
ตัวอย่างการคำนวณ: `cientifica.py` ```py from tkinter import * import math import tkinter.messagebox root = Tk() root.title("Scientific Calculator") root.configure(พื้นหลัง="white") root.resizable(width=False, height=False) root.geometry("480x568+450+90") calc = Frame(root) calc.grid() คลาส Calc(): def __init__(self): self.total = 0 self.current = "" self.input_value = True self.check_sum = False self.op = "" self.result = False def number_enter(self, num): self.result = False firstnum = txtDisplay.get() Secondnum = str (num) ถ้า self.input_value: self.current = Secondnum self.input_value = False อย่างอื่น: ถ้า Secondnum == ".": ถ้า Secondnum ใน firstnum: return self.current = firstnum + Secondnum self.display (self.current) def sum_of_total (ตนเอง): self.result = True self.current = float (self.current) ถ้า self.check_sum == True: self.valid_function () อื่น ๆ : self.total = float (txtDisplay.get ()) def display (ตนเอง ค่า): txtDisplay.delete(0, END) txtDisplay.insert(0, ค่า) def valid_function(self): ถ้า self.op == "เพิ่ม": self.total += self.current ถ้า self.op == "sub": self.total -= self.current ถ้า self.op == "multi": self.total *= self.current ถ้า self.op == "แบ่ง": self.total /= self.current ถ้า self.op == "mod": self.total %= self.current self.input_value = True self.check_sum = False self.display (self.total) การดำเนินการ def (self, op): self.current = float ( self.current) ถ้า self.check_sum: self.valid_function() elif ไม่ใช่ self.result: self.total = self.current self.input_value = True self.check_sum = True self.op = op self.result = False def clear_entry( self): self.result = False self.current = "0" self.display (0) self.input_value = True def all_clear_entry (ตนเอง): self.clear_entry () self.total = 0 def pi (ตนเอง): self ผลลัพธ์ = เท็จ self.current = math.pi self.display (self.current) def tau (ตนเอง): self.result = เท็จ self.current = math.tau self.display (self.current) def e (ตัวเอง): self.result = เท็จ self.current = math.e self.display (self.current) def mathPM (ตนเอง): self.result = เท็จ self.current = - (ลอย (txtDisplay.get ())) self.display ( self.current) def กำลังสอง (ตนเอง): self.result = เท็จ self.current = math.sqrt (ลอย (txtDisplay.get ())) self.display (self.current) def cos (ตนเอง): self.result = self.current เท็จ = math.cos(math.radians(float(txtDisplay.get()))) self.display(self.current) def cosh(self): self.result = False self.current = math.cosh( math.radians (float (txtDisplay.get ()))) self.display (self.current) def tan (self): self.result = False self.current = math.tan (math.radians (float (txtDisplay.get ()))) self.display(self.current) def tanh(self): self.result = False self.current = math.tanh(math.radians(float(txtDisplay.get()))) self.display( self.current) def sin (ตนเอง): self.result = False self.current = math.sin (math.radians (ลอย (txtDisplay.get ()))) self.display (self.current) def sinh (ตนเอง) : self.result = False self.current = math.sinh(math.radians(float(txtDisplay.get()))) self.display(self.current) def log(self): self.result = False self.current = math.log(float(txtDisplay.get())) self.display(self.current) def exp(self): self.result = False self.current = math.exp(float(txtDisplay.get())) self.display (self.current) def acosh (ตนเอง): self.result = เท็จ self.current = math.acosh (ลอย (txtDisplay.get ())) self.display (self.current) def asinh (ตัวเอง): self.result = เท็จ self.current = math.asinh (ลอย (txtDisplay.get ())) self.display (self.current) def expm1 (ตนเอง): self.result = เท็จ self.current = math.expm1 (ลอย (txtDisplay.get())) self.display(self.current) def lgamma(self): self.result = False self.current = math.lgamma(float(txtDisplay.get())) self.display(self. ปัจจุบัน) องศา def (ตัวเอง): self.result = เท็จ self.current = math.degrees (ลอย (txtDisplay.get ())) self.display (self.current) def log2 (ตนเอง): self.result = ตนเองเท็จ .current = math.log2(float(txtDisplay.get())) self.display(self.current) def log10(self): self.result = False self.current = math.log10(float(txtDisplay.get()) )) self.display(self.current) def log1p(self): self.result = False self.current = math.log1p(float(txtDisplay.get())) self.display(self.current) added_value = Calc( ) txtDisplay = Entry(calc, font=("Helvetica", 20, "bold"), bg="black", fg="white", bd=30, width=28, justify=RIGHT) txtDisplay.grid(แถว) =0, คอลัมน์=0, columnspan=4, pady=1) txtDisplay.insert(0, "0") numberpad = "789456123" i = 0 btn = [] สำหรับ j อยู่ในช่วง (2, 5): สำหรับ k ใน range(3): btn.append(Button(calc, width=6, height=2, bg="black", fg="white", font=("Helvetica", 20, "bold"), bd=4 , text=numberpad[i])) btn[i].grid(row=j, column=k, pady=1) btn[i]["command"] = lambda x = numberpad[i]: added_value.number_enter( x) i += 1 btnClear = Button(calc, text=chr(67), width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd= 4, command=added_value.clear_entry).grid(row=1, column=0, pady=1) btnAllClear = Button(calc, text=chr(67) + chr(69), width=6, height=2, bg ="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=added_value.all_clear_entry).grid(row=1, column=1, pady=1) btnsq = Button(calc , text="\u221A", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=added_value.squared).grid( แถว=1, คอลัมน์=2, pady=1) btnAdd = Button(calc, text="+", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold "), bd=4, command=lambda:added_value.operation("add")).grid(row=1, column=3, pady=1) btnSub = Button(calc, text="-", width=6 , height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.operation("sub")).grid(row=2, คอลัมน์=3, pady=1) btnMul = ปุ่ม(calc, text="x", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd =4, command=lambda:added_value.operation("multi")).grid(row=3, column=3, pady=1) btnDiv = Button(calc, text="/", width=6, height=2 , bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.operation("divide")).grid(row=4, คอลัมน์=3, pady=1) btnZero = Button(calc, text="0", width=6, height=2, bg="black", fg="white", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.number_enter(0)).grid(row=5, column=0, pady=1) btnDot = Button(calc, text=".", width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, command=lambda:added_value.number_enter(".")).grid(row=5, column=1, ข้าวเปลือก =1) btnPM = Button(calc, text=chr(177), width=6, height=2, bg="powder blue", font=("Helvetica", 20, "bold"), bd=4, คำสั่ง =added_value.mathPM).grid(row=5, column=2, pady=1) btnEquals = Button(calc, text="=", width=6, height=2, bg="powder blue", font=( "Helvetica", 20, "ตัวหนา"), bd=4, command=added_value.sum_of_total).grid(row=5, column=3, pady=1) # ... ```
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence