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DEKmGRgYGH4TYzMuPJcY5+OzHQNQnA4oBgDr1Cmq0V62UAAAAABJRU5ErkJggg==\n
'''
# Function for convert image to Base64 string
import base64
def getBase64OfFile(file_name):
with open(file_name, "rb") as file:
print(base64.b64encode(file.read()))
def calc():
ret ="--------------------------------------------------"
ret += "\n" + " Объём сделки 1: " + "%-10s" % volume1_entry.get()
ret += " Цена 1: " + price1_entry.get() + "\n"
ret += " Объём сделки 2: " + "%-10s" % volume2_entry.get()
ret += " Цена 2: " + price2_entry.get() + "\n"
ret += " Комиссия: " + percent_entry.get() + "\n"
ret1 = "Введите число больше 0" + "\n"
ret2 = "Ошибка ввода! Введите число больше 0" + "\n"
ret3 = "Комиссия % не более 2-х знаков после запятой!" + "\n"
ret4 = "Введите не более 8 знаков после запятой!" + "\n"
ret5 = "Комиссия % не более 2-х знаков до запятой!" + "\n"
try:
percent = float(percent_entry.get().replace(',', '.'))
volume1 = float(volume1_entry.get().replace(',', '.'))
volume2 = float(volume2_entry.get().replace(',', '.'))
price1 = float(price1_entry.get().replace(',', '.'))
price2 = float(price2_entry.get().replace(',', '.'))
except ValueError:
return calculated_text.insert(END, ret2)
if percent <= 0 or volume1 <= 0 or volume2 <=0 or price1 <= 0 or price2 <= 0:
return calculated_text.insert(END, ret1)
if percent != round(percent,2):
return calculated_text.insert(END, ret3)
if percent > 99:
return calculated_text.insert(END, ret5)
if volume1 != round(volume1,8) or volume2 != round(volume2,8) or price1 != round(price1,8) or price2 != round(price2,8):
return calculated_text.insert(END, ret4)
i = (volume1/price1)+(volume2/price2)
a = ((100+percent)*(volume1+volume2))/100
z = a/i
y = z/((100-percent)/100)
ret += (" Цена для выхода в ноль: {price:0.8f}\n".format(price=y))
calculated_text.insert(END, ret)
def clear():
volume1_entry.delete('0', END)
volume2_entry.delete('0', END)
percent_entry.delete('0', END)
price1_entry.delete('0', END)
price2_entry.delete('0', END)
def erase():
calculated_text.delete('1.0', END)
root = Tk()
root.resizable(width=False, height=False)
root.title("Калькулятор безубытка")
root.geometry("420x300+300+300")
calculated_text = Text(root,height=10, width=50)
volume1_label = Label(text=" Объём сделки 1")
volume2_label = Label(text=" Объём сделки 2")
price1_label = Label(text="Цена 1")
price2_label = Label(text="Цена 2")
percent_label = Label(text=" Комиссия %")
volume1_label.grid(row=0, column=0, sticky="w")
volume2_label.grid(row=1, column=0, sticky="w")
percent_label.grid(row=2, column=0, sticky="w")
price1_label.grid(row=0, column=2, sticky="w")
price2_label.grid(row=1, column=2, sticky="w")
volume1_entry = Entry(width=10, justify=CENTER)
volume2_entry = Entry(width=10, justify=CENTER)
percent_entry = Entry(width=10, justify=CENTER)
price1_entry = Entry(width=10, justify=CENTER)
price2_entry = Entry(width=10, justify=CENTER)
volume1_entry.grid(row=0,column=1, padx=5, pady=5)
volume2_entry.grid(row=1,column=1, padx=5, pady=5)
percent_entry.grid(row=2,column=1, padx=5, pady=5)
price1_entry.grid(row=0,column=2, padx=53, pady=5)
price2_entry.grid(row=1,column=2, padx=53, pady=5)
# вставка начальных данных
volume1_entry.insert(0, "0.1")
volume2_entry.insert(0, "0.15")
percent_entry.insert(0, "0.2")
price1_entry.insert(0, "0.00000300")
price2_entry.insert(0, "0.00000200")
#добавление кнопок
display_button = Button(text="Вывести", command=calc)
clear_button = Button(text="Сбросить", command=clear)
erase_button = Button(text="Очистить результаты", command=erase)
display_button.grid(row=3, column=0, padx=5, pady=5, sticky="e")
clear_button.grid(row=3, column=1, padx=5, pady=5, sticky="e")
erase_button.grid(row=3, column=2, padx=25, pady=5, sticky="w")
calculated_text.grid(row=4, column=0, sticky='nsew', columnspan=3)
scrollb = Scrollbar(root, command=calculated_text.yview)
scrollb.grid(row=4, column=4, sticky='nsew')
#calculated_text['yscrollcommand'] = scrollb.set
calculated_text.configure(yscrollcommand=scrollb.set)
# Set icon to the windows title
img = PhotoImage(data=icon)
root.tk.call('wm', 'iconphoto', root._w, img)
#root.iconbitmap("bitcoin.ico")
#getBase64OfFile("bitcoin.png")
root.mainloop()