Jak w tym kodzie można zastosować klasy, w którym momencie (w tym jakieś dziedziczenie)? Czy można dodać jakiś wyjątek i żeby był on wyświetlany w jakimś polu np. dzielenie przez 0 (Error) ? I jeszcze jedno pytanie czy można dodać aby wyświetlało nam pieniądze jakie mamy, żeby wiedzieć ile można wydać. Wybaczcie za taki opis ,ale jestem totalnie zielony w Pythonie i nie wiem jak się za to zabrać, jak ktoś wie jak to zrobić i mógłby rozpisać to bym był bardzo wdzięczny :)
from tkinter import*
import random
import time
import tkinter as tk
from tkinter import font as tkfont
root = Tk()
root.geometry("1366x768+0+0")
root.title("System zarządzania sklepem")
text_Input = StringVar()
operator = ""
mojFont = tkfont.Font(family='arial', size=16, weight='bold')
root.option_add ("* Font", mojFont)
Tops = Frame (root, width = 1366,height = 50, bg= "red", relief=SUNKEN)
Tops.pack(side=TOP)
f1 = Frame (root, width = 800,height = 700, relief=SUNKEN)
f1.pack(side=LEFT)
f2 = Frame (root, width = 300,height = 700, relief=SUNKEN)
f2.pack(side=RIGHT)
#Czas
localtime = time.asctime(time.localtime(time.time()))
#Informacje
lblInfo = Label(Tops, font = ("Helvetica", 50, "bold"), text = "System zarządzania sklepem", fg = "Steel Blue", bd = 0, anchor = "w")
lblInfo.grid(row = 0, column = 0)
lblInfo = Label(Tops, font = mojFont,text = localtime, fg = "Steel Blue", bd = 0, anchor = "w")
lblInfo.grid(row = 1, column = 0)
#Kalkulator
def btnClick(numbers):
global operator
operator = operator + str(numbers)
text_Input.set(operator)
def btnClearDisplay():
global operator
operator = ""
text_Input.set("")
def btnEqualsInput():
global operator
sumup = str(eval(operator))
text_Input.set(sumup)
operator = ""
def Ref():
x = random.randint(10908, 500876)
randomRef = str(x)
rand.set(randomRef)
CoF = float(Frytki.get())
CoC = float(Cola.get())
CoL = float(Lazania.get())
CoH = float(Hamburger.get())
CoP = float(Pieczonykurczak.get())
CoPizza = float(Pizza.get())
CostofFrytki = CoF * 50.00
CostofCola = CoC * 15.00
CostofLazania = CoL * 38.87
CostofHamburger = CoH * 25.00
CostofPieczonykurczak = CoP * 88.69
CostofPizza = CoPizza * 63.99
CostofPosilek = "zł", str('%.2f' % (CostofFrytki + CostofCola + CostofLazania + CostofHamburger+ CostofPieczonykurczak + CostofPizza))
PayTax = ((CostofFrytki + CostofCola + CostofLazania + CostofHamburger+ CostofPieczonykurczak + CostofPizza) * 0.23)
TotalCost = (CostofFrytki + CostofCola + CostofLazania + CostofHamburger+ CostofPieczonykurczak + CostofPizza)
Ser_wis = ((CostofFrytki + CostofCola + CostofLazania + CostofHamburger+ CostofPieczonykurczak + CostofPizza)/99)
Serwis = "zł", str('%.2f' % Ser_wis)
OverallCost = "zł", str('%.2f' % (PayTax + TotalCost + Ser_wis))
PaidTax = "zł", str('%.2f' % PayTax)
Koszt.set(CostofPosilek)
Podatek.set(PaidTax)
Sumaczesciowa.set(CostofPosilek)
Kosztcalkowity.set(OverallCost)
Serwis_Charge.set(Serwis)
def qExit():
root.destroy()
def Reset():
rand.set("")
Frytki.set("")
Hamburger.set("")
Lazania.set("")
Pizza.set("")
Pieczonykurczak.set("")
Cola.set("")
Kosztcalkowity.set("")
Koszt.set("")
Podatek.set("")
Sumaczesciowa.set("")
Serwis_Charge.set("")
txtDisplay = Entry(f2, font = mojFont,textvariable=text_Input, bd = 30, insertwidth = 4, bg = "red", justify = "right")
txtDisplay.grid(columnspan=4)
btn7 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "7", bg = "red", command = lambda: btnClick(7)).grid (row= 2, column = 0)
btn8 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "8", bg = "red", command = lambda: btnClick(8)).grid (row= 2, column = 1)
btn9 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "9", bg = "red", command = lambda: btnClick(9)).grid (row= 2, column = 2)
Addition = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "+", bg = "red", command = lambda: btnClick("+")).grid (row= 2, column = 3)
btn4 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "4", bg = "red", command = lambda: btnClick(4)).grid (row= 3, column = 0)
btn5 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "5", bg = "red", command = lambda: btnClick(5)).grid (row= 3, column = 1)
btn6 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "6", bg = "red", command = lambda: btnClick(6)).grid (row= 3, column = 2)
Subtraction = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "-", bg = "red", command = lambda: btnClick("-")).grid (row= 3, column = 3)
btn1 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "1", bg = "red", command = lambda: btnClick(1)).grid (row= 4, column = 0)
btn2 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "2", bg = "red", command = lambda: btnClick(2)).grid (row= 4, column = 1)
btn3 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "3", bg = "red", command = lambda: btnClick(3)).grid (row= 4, column = 2)
Multiply = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "*", bg = "red", command = lambda: btnClick("*")).grid (row= 4, column = 3)
btn0 = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "0", bg = "red", command = lambda: btnClick(0)).grid (row= 5, column = 0)
btnClear = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "C", bg = "red", command = btnClearDisplay).grid (row= 5, column = 1)
btnEquals = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "=", bg = "red", command = btnEqualsInput).grid (row= 5, column = 2)
Division = Button(f2, padx = 16, pady = 16, bd = 8, fg = "black", font = mojFont, text = "/", bg = "red", command = lambda: btnClick("/")).grid (row= 5, column = 3)
# Restauracja
rand = StringVar()
Frytki = StringVar()
Hamburger = StringVar()
Lazania = StringVar()
Pizza = StringVar()
Pieczonykurczak = StringVar()
Cola = StringVar()
Serwis_Charge = StringVar()
Kosztcalkowity = StringVar()
Koszt = StringVar()
Podatek = StringVar()
Sumaczesciowa = StringVar()
lblReferencje = Label(f1, font=mojFont, text= "Numer zamówienia", bd = 16, anchor = "w")
lblReferencje.grid(row= 0, column= 0)
txtReferencje = Entry(f1, font=mojFont, textvariable = rand, bd = 10, insertwidth=4, bg = "red", justify = "right")
txtReferencje.grid(row= 0, column= 1)
lblFrytki = Label(f1, font=mojFont, text= "Słodycze", bd = 16, anchor = "w")
lblFrytki.grid(row= 1, column= 0)
txtFrytki = Entry(f1, font=mojFont, textvariable = Frytki, bd = 10, insertwidth=4, bg = "red", justify = "right")
txtFrytki.grid(row= 1, column= 1)
lblHamburger = Label(f1, font=mojFont, text= "Napoje", bd = 16, anchor = "w")
lblHamburger.grid(row= 2, column= 0)
txtHamburger = Entry(f1, font=mojFont, textvariable = Hamburger, bd = 10, insertwidth=4, bg = "red", justify = "right")
txtHamburger.grid(row= 2, column= 1)
lblLazania = Label(f1, font=mojFont, text= "Mrożonki", bd = 16, anchor = "w")
lblLazania.grid(row= 3, column= 0)
txtLazania = Entry(f1, font=mojFont, textvariable = Lazania, bd = 10, insertwidth=4, bg = "red", justify = "right")
txtLazania.grid(row= 3, column= 1)
lblPizza = Label(f1, font=mojFont, text= "Warzywa i owoce", bd = 16, anchor = "w")
lblPizza.grid(row= 4, column= 0)
txtPizza = Entry(f1, font=mojFont, textvariable = Pizza, bd = 10, insertwidth=4, bg = "red", justify = "right")
txtPizza.grid(row= 4, column= 1)
lblPieczonykurczak = Label(f1, font=mojFont, text= "Wyroby mięsne", bd = 16, anchor = "w")
lblPieczonykurczak.grid(row= 5, column= 0)
txtPieczonykurczak = Entry(f1, font=mojFont, textvariable = Pieczonykurczak, bd = 10, insertwidth=4, bg = "red", justify = "right")
txtPieczonykurczak.grid(row= 5, column= 1)
lblCola = Label(f1, font=mojFont, text= "Chemia", bd = 16, anchor = "w")
lblCola.grid(row= 6, column= 0)
txtCola = Entry(f1, font=mojFont, textvariable = Cola, bd = 10, insertwidth=4, bg = "red", justify = "right")
txtCola.grid(row= 6, column= 1)
#Restauracja 2
lblKoszt = Label(f1, font=mojFont, text= "Koszt jedzenia", bd = 16, anchor = "w")
lblKoszt.grid(row= 0, column= 2)
txtKoszt = Entry(f1, font=mojFont, textvariable = Koszt, bd = 10, insertwidth=4, bg = "white", justify = "right")
txtKoszt.grid(row= 0, column= 3)
lblSerwis_Charge = Label(f1, font=mojFont, text= "Koszt obsługi", bd = 16, anchor = "w")
lblSerwis_Charge.grid(row= 1, column= 2)
txtSerwis_Charge = Entry(f1, font=mojFont, textvariable = Serwis_Charge, bd = 10, insertwidth=4, bg = "white", justify = "right")
txtSerwis_Charge.grid(row= 1, column= 3)
lblPodatek = Label(f1, font=mojFont, text= "Podatek", bd = 16, anchor = "w")
lblPodatek.grid(row= 2, column= 2)
txtPodatek = Entry(f1, font=mojFont, textvariable = Podatek, bd = 10, insertwidth=4, bg = "white", justify = "right")
txtPodatek.grid(row= 2, column= 3)
lblSumaczesciowa = Label(f1, font=mojFont, text= "Suma częściowa", bd = 16, anchor = "w")
lblSumaczesciowa.grid(row= 3, column= 2)
txtSumaczesciowa = Entry(f1, font=mojFont, textvariable = Sumaczesciowa, bd = 10, insertwidth=4, bg = "white", justify = "right")
txtSumaczesciowa.grid(row= 3, column= 3)
lblKosztcalkowity = Label(f1, font=mojFont, text= "Koszt całkowity", bd = 16, anchor = "w")
lblKosztcalkowity.grid(row= 4, column= 2)
txtKosztcalkowity = Entry(f1, font=mojFont, textvariable = Kosztcalkowity, bd = 10, insertwidth=4, bg = "white", justify = "right")
txtKosztcalkowity.grid(row= 4, column= 3)
#Przyciski
btnTotal = Button(f1, padx = 16, pady = 8, bd = 16, fg = "black",font=mojFont, width = 10, text = "Całość", bg = "red", command = Ref).grid(row = 7, column = 1)
btnReset = Button(f1, padx = 16, pady = 8, bd = 16, fg = "black",font=mojFont, width = 10, text = "Reset", bg = "red", command = Reset).grid(row = 7, column = 2)
btnExit = Button(f1, padx = 16, pady = 8, bd = 16, fg = "black",font=mojFont, width = 10, text = "Wyjście", bg = "red", command = qExit).grid(row = 7, column = 3)
root.mainloop()