如何从 tkinter 上的 Checkbutton 更改
How do I change from the Checkbutton on tkinter
所以我是 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()
很简单,只需删除此复选框以及与之关联的所有内容,例如检查此复选框等。
对于初学者,在删除这些行后调整列表:
if (japp.get()):
...
japp = IntVar()
Checkbutton(hej, text="Kostnad per styck", variable=japp).place(x=10, y=50)
Offtop:
这很奇怪,如果您创建了该代码,您应该能够修改它。您应该做的第一件事是在 类 中组织您的代码,以便于管理和调试...
所以我是 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()
很简单,只需删除此复选框以及与之关联的所有内容,例如检查此复选框等。
对于初学者,在删除这些行后调整列表:
if (japp.get()):
...
japp = IntVar()
Checkbutton(hej, text="Kostnad per styck", variable=japp).place(x=10, y=50)
Offtop:
这很奇怪,如果您创建了该代码,您应该能够修改它。您应该做的第一件事是在 类 中组织您的代码,以便于管理和调试...