Home
О нас
Products
Services
Регистрация
Войти
Поиск
anastasiasakun062
@anastasiasakun062
July 2023
1
21
Report
помогите пожалуйста создать программный код вот такого калькулятора, ниже скину. отдам 50 баллов.
Please enter comments
Please enter your name.
Please enter the correct email address.
Agree to
terms of service
You must agree before submitting.
Send
Answers & Comments
yamabiko
Verified answer
from tkinter import *
class Main(Frame):
def __init__(self, root):
super(Main, self).__init__(root)
self.build()
def build(self):
self.formula = "0"
self.lbl = Label(text=self.formula, font=("Times New Roman", 21, "bold"), bg="#000", foreground="#FFF")
self.lbl.place(x=11, y=50)
btns = [
"C", "DEL", "*", "=",
"1", "2", "3", "/",
"4", "5", "6", "+",
"7", "8", "9", "-",
"(", "0", ")", "X^2"
]
x = 10
y = 140
for bt in btns:
com = lambda x=bt: self.logicalc(x)
Button(text=bt, bg="#FFF",
font=("Times New Roman", 15),
command=com).place(x=x, y=y,
width=115,
height=79)
x += 117
if x > 400:
x = 10
y += 81
def logicalc(self, operation):
if operation == "C":
self.formula = ""
elif operation == "DEL":
self.formula = self.formula[0:-1]
elif operation == "X^2":
self.formula = str((eval(self.formula))**2)
elif operation == "=":
self.formula = str(eval(self.formula))
else:
if self.formula == "0":
self.formula = ""
self.formula += operation
self.update()
def update(self):
if self.formula == "":
self.formula = "0"
self.lbl.configure(text=self.formula)
if __name__ == '__main__':
root = Tk()
root["bg"] = "#000"
root.geometry("485x550+200+200")
root.title("Калькулятор")
root.resizable(False, False)
app = Main(root)
app.pack()
root.mainloop()
Примерно такой, если не сложно поставь лучший ответ
2 votes
Thanks 1
More Questions From This User
See All
anastasiasakun062
July 2023 | 0 Ответы
1 8 2 64a53815d61a7
Answer
anastasiasakun062
June 2023 | 0 Ответы
2f2df50e3510b872b809ca3678b853a3
Answer
anastasiasakun062
July 2022 | 0 Ответы
pomogite pozhalujsta napishite 10 ochen interesnyh faktov iz detstva aleksandra pu
Answer
×
Report "помогите пожалуйста создать программный код вот такого калькулятора, ниже скину. отдам 50 баллов"
Your name
Email
Reason
-Select Reason-
Pornographic
Defamatory
Illegal/Unlawful
Spam
Other Terms Of Service Violation
File a copyright complaint
Description
Helpful Links
О нас
Политика конфиденциальности
Правила и условия
Copyright
Контакты
Helpful Social
Get monthly updates
Submit
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
from tkinter import *class Main(Frame):
def __init__(self, root):
super(Main, self).__init__(root)
self.build()
def build(self):
self.formula = "0"
self.lbl = Label(text=self.formula, font=("Times New Roman", 21, "bold"), bg="#000", foreground="#FFF")
self.lbl.place(x=11, y=50)
btns = [
"C", "DEL", "*", "=",
"1", "2", "3", "/",
"4", "5", "6", "+",
"7", "8", "9", "-",
"(", "0", ")", "X^2"
]
x = 10
y = 140
for bt in btns:
com = lambda x=bt: self.logicalc(x)
Button(text=bt, bg="#FFF",
font=("Times New Roman", 15),
command=com).place(x=x, y=y,
width=115,
height=79)
x += 117
if x > 400:
x = 10
y += 81
def logicalc(self, operation):
if operation == "C":
self.formula = ""
elif operation == "DEL":
self.formula = self.formula[0:-1]
elif operation == "X^2":
self.formula = str((eval(self.formula))**2)
elif operation == "=":
self.formula = str(eval(self.formula))
else:
if self.formula == "0":
self.formula = ""
self.formula += operation
self.update()
def update(self):
if self.formula == "":
self.formula = "0"
self.lbl.configure(text=self.formula)
if __name__ == '__main__':
root = Tk()
root["bg"] = "#000"
root.geometry("485x550+200+200")
root.title("Калькулятор")
root.resizable(False, False)
app = Main(root)
app.pack()
root.mainloop()
Примерно такой, если не сложно поставь лучший ответ