So I'm very new to Tkinter and don't really know how to use it. I looked up some similar code and found a solution for how to get the text boxes(e1)(e6) I use to register the values, but the downside was that I needed to use the Checkbox that's in line 52. Does anyone know how I could stop using the checkbox, and just put in the values without having to click the checkbox?
#importerar tkinter
from tkinter import *
from tkinter import ttk
#All calculations are made here, which are then displayed and registered before you save the receipt.
def show():
totalt = 0
if (japp.get()):
pris = int(e1.get())
kvk = int(e6.get())
totalt = int(pris * kvk)
tempList = [[e1.get(), e6.get(), totalt]]
tempList.sort(key=lambda e: e[1], reverse=True)
for i, (pris, kvk, totalt) in enumerate(tempList, start=1):
listBox.insert("", "end", values=(pris, kvk, totalt))
sum1 = 0.0
for lmao in listBox.get_children():
sum1 = float(listBox.item(lmao, 'values')[2])
totaltText.set(sum1)
#Here the receipt is saved, geom that it goes through each number and then enters it in the txt file.
def spara():
for lmao in listBox.get_children():
pris = str(listBox.item(lmao, 'values')[0])
kvk = str(listBox.item(lmao, 'values')[1])
totalt = str(listBox.item(lmao, 'values')[2])
txt = open("Kvitto.txt", "w")
txt.write("kvantitet: " kvk ". Pris per vara: " pris ". total kostnad: " totalt ". ")
txt.close
hej = Tk()
hej.title("Kvitto system")
hej.geometry("650x650")
global e1
global totaltText
global balText
totaltText = StringVar()
balText = IntVar()
#all text som visas
Label(hej, text="Kvitto system", font="arial 22 bold" ,bg="white").place(x=5, y=10)
Label(hej, text="Antal", font="arial 13").place(x=10, y=80)
japp = IntVar()
Checkbutton(hej, text="Kostnad per styck", variable=japp).place(x=10, y=50)
#skriv rutorna, där man svarar på kvantitet(e6) och kostnad(e1)
e1 = Entry(hej)
e1.place(x=200, y=80)
e6 = Entry(hej)
e6.place(x=200, y=50)
totalt = Label(hej, text="", font="arial 22 bold", textvariable=totaltText)
totalt.place(x=650, y=10)
#Alla knappar som används i programmet
Button(hej, text="Lägg till varor", command=show, height=3, width=13).place(x=10, y=220)
cols = ('Pris', 'Kvantitet', 'total kostnad')
listBox = ttk.Treeview(hej, columns=cols, show='headings')
Button(hej, text="Spara Kvitto", command=spara, height=3, width=13).place(x=150, y=220)
for col in cols:
listBox.heading(col, text=col)
listBox.grid(row=1, column=0, columnspan=2)
listBox.place(x=10, y=300)
hej.mainloop()
CodePudding user response:
It's simple, just remove this checkbox and everything associated with it, like checks about this checkbox etc.
For starter, adjust tabulation after removing these lines:
if (japp.get()):
...
japp = IntVar()
Checkbutton(hej, text="Kostnad per styck", variable=japp).place(x=10, y=50)
Offtop:
That's strange, if you created that code, you should be able to modify it. First thing you should do is organize your code in classes, to be easier to manage and debug...