所以我對 Tkinter 很陌生,并不真正知道如何使用它。我查找了一些類似的代碼并找到了如何獲取用于注冊值的文本框(e1)(e6)的解決方案,但缺點是我需要使用第 52 行中的復選框。有誰知道如何我可以停止使用復選框,只需輸入值而無需單擊復選框?
#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()
uj5u.com熱心網友回復:
這很簡單,只需洗掉此復選框以及與之相關的所有內容,例如有關此復選框的檢查等。
首先,在洗掉這些行后調整制表:
if (japp.get()):
...
japp = IntVar()
Checkbutton(hej, text="Kostnad per styck", variable=japp).place(x=10, y=50)
關閉頂部:
這很奇怪,如果你創建了那個代碼,你應該可以修改它。您應該做的第一件事是在類中組織您的代碼,以便更易于管理和除錯......
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/474311.html
下一篇:Tkinter按鈕不堆疊在左側
