I have check boxes , generated by a for loop.
def MakeMaterialsButtons(self):
self.ChoosingVariable = ctk.IntVar(value=0)
CallDB = aoracandlestudiodb.cursor()
query = 'SELECT idmaterials FROM materials WHERE mat_category = %s '
CallDB.execute(query, (StickersName,))
Stickers_Categories_ID3 = CallDB.fetchall()
i = 1
j = 1
mat_distance = 10
x_mat_distance = 10
for stickers_item in Stickers_Categories_ID3:
get_mat_ID_str = str(stickers_item)
get_mat_ID = get_mat_ID_str[1:-2]
int(get_mat_ID)
if mat_distance >= 150:
x_mat_distance = x_mat_distance + 200
mat_distance = 10
self.MakeOrderButtonsForStickers(get_mat_ID, mat_distance, x_mat_distance)
j = j + 1
mat_distance = mat_distance + 60
def MakeOrderButtonsForStickers(self, get_mat_ID, mat_distance, x_mat_distance):
get_mat_name = get_NameOfMaterial(get_mat_ID)
ItembyCategoryCheckBox = ctk.CTkCheckBox(self.StickersFrame, text=get_mat_name,
command=lambda: self.Add_To_Order_Materials(get_mat_ID, get_mat_name),
fg_color="#a881af", variable=self.ChoosingVariable,
onvalue="1", offvalue="0", width=150, height=40,
text_color='black', font=("arial bold", 20),
border_width=4,
border_color='black')
ItembyCategoryCheckBox.place(x=x_mat_distance, y=mat_distance)
And this is the function when i am checking it.
def Add_To_Order_Materials(self, Mat_ID, mat_name):
print(self.ChoosingVariable.get())
Mat_Price = get_PriceOfMaterial(Mat_ID)
if self.ChoosingVariable.get() == 1:
if mat_name != self.Name_Order_Counter:
self.Item_Order_Counter = 1
self.Item_Order_Distance = self.Item_Order_Distance + 30
self.Name_Order_Counter = mat_name
self.Material_Order_Text = ctk.CTkLabel(self.ordertotalframe, text=mat_name, font=("arial bold", 20),
text_color='black')
self.Material_Order_Text.place(x=55, y=self.Item_Order_Distance)
self.Material_quantity_text = ctk.CTkLabel(self.ordertotalframe, text=(str(self.Item_Order_Counter) + "x"),
font=("arial bold", 20), text_color='black')
self.Material_quantity_text.place(x=210, y=self.Item_Order_Distance)
self.Material_price_text = ctk.CTkLabel(self.ordertotalframe, text=(str(Mat_Price) + " €"),
font=("arial bold", 20), text_color='black')
self.Material_price_text.place(x=300, y=self.Item_Order_Distance)
self.Item_Order_Counter = self.Item_Order_Counter + 1
self.Order_Total_price = self.Order_Total_price + Mat_Price
self.Order_Total_price_Label.configure(text=(str(self.Order_Total_price) + " €"))
self.Material_Order_Text.place()
else:
self.Material_quantity_text.configure(text=(str(self.Item_Order_Counter) + "x"))
self.Material_Order_Text.configure(text=mat_name)
self.Item_Order_Counter = self.Item_Order_Counter + 1
self.Order_Total_price = self.Order_Total_price + Mat_Price
self.Order_Total_price_Label.configure(text=(str(self.Order_Total_price) + " €"))
else:
self.Name_Order_Counter = ""
self.Material_Order_Text.place_forget()
self.Material_quantity_text.place_forget()
self.Material_price_text.place_forget()
self.Item_Order_Distance = self.Item_Order_Distance - 30
self.Order_Total_price = self.Order_Total_price - Mat_Price
self.Order_Total_price_Label.configure(text=(str(round(self.Order_Total_price, 2)) + " €"))
So its basicly adds the material price on a frame which is getting the total of an order. If i check two of the options i want , and then i want to remove the first option i checked, it just doing these lines
self.Item_Order_Distance = self.Item_Order_Distance - 30
self.Order_Total_price = self.Order_Total_price - Mat_Price
self.Order_Total_price_Label.configure(text=(str(round(self.Order_Total_price, 2)) + "
It doesnt remove the previous choice , but only the last i checked. Any ideas ? Do i have to add a table and do something with that , on every each button which is made? How can i do that
Return the sticker in your
MakeOrderButtonsForStickersfunction like so:Then you can create a member variable of your class, like
sticker_checkboxes, and assign by index in the for-loop usingenumerate.Now you have a list of your checkboxes, in the order you created them. You could also make
sticker_checkboxesas a dict, and index onget_mat_ID, up to you.