好吧,假设我有一个按钮,每次我按下它,它都会生成一个标签。 我有一个删除按钮,每次我按下它时,它只会删除最新的标签。 但是如果我删除最新的一个,那么删除按钮什么都不做。我希望每次按下它时,我都会删除最新生成的标签。不仅是最后一个。
我确实通过生成器按钮尝试过,不仅生成了标签,还生成了一个新的删除按钮,但这不是我想要的方式,因为我在屏幕上到处都是删除按钮
def MakeMaterialsButtons(self):
StickersName = "Stickers"
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
BagsName = "Bags"
CardsName = "Cards"
AbalazName = "Ampalaz"
ColorsName = "Colors"
Diffussers = "Diffusers"
CallDB = aoracandlestudiodb.cursor()
query2 = 'SELECT idmaterials FROM materials WHERE mat_category = %s OR mat_category = %s OR mat_category = %s ' \
'OR mat_category = %s'
CallDB.execute(query2, (CardsName, AbalazName, ColorsName, Diffussers))
Random_Categories_ID3 = CallDB.fetchall()
i = 1
random_mat_distance = 10
random_x_mat_distance = 10
for random_item in Random_Categories_ID3:
get_random_mat_ID_str = str(random_item)
get_random_mat_ID = get_random_mat_ID_str[1:-2]
int(get_random_mat_ID)
if random_mat_distance >= 150:
random_x_mat_distance = random_x_mat_distance + 200
random_mat_distance = 10
self.MakeOrderButtonsForRandom(get_random_mat_ID, random_mat_distance, random_x_mat_distance)
i = i + 1
random_mat_distance = random_mat_distance + 60
CallDB = aoracandlestudiodb.cursor()
query3 = 'SELECT idmaterials FROM materials WHERE mat_category = %s '
CallDB.execute(query3, (BagsName,))
Bags_Categories_ID3 = CallDB.fetchall()
i = 1
self.BagsButtonsList = []
Bags_mat_distance = 10
Bags_x_mat_distance = 10
for Bags_item in Bags_Categories_ID3:
get_Bags_mat_ID_str = str(Bags_item)
get_Bags_mat_ID = get_Bags_mat_ID_str[1:-2]
int(get_Bags_mat_ID)
self.BagsButtonsList.append(get_Bags_mat_ID)
if Bags_mat_distance >= 100:
Bags_x_mat_distance = random_x_mat_distance + 200
Bags_mat_distance = 10
self.MakeOrderButtonsForBags(get_Bags_mat_ID, Bags_mat_distance, Bags_x_mat_distance)
i = i + 1
Bags_mat_distance = Bags_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)
def MakeOrderButtonsForRandom(self, get_mat_ID, mat_distance, x_mat_distance):
get_mat_name = get_NameOfMaterial(get_mat_ID)
ItembyCategoryCheckBox = ctk.CTkCheckBox(self.RandomMaterialsFrame, 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)
def MakeOrderButtonsForBags(self, get_mat_ID, mat_distance, x_mat_distance):
print(self.ChoosingVariable)
get_mat_name = get_NameOfMaterial(get_mat_ID)
ItembyCategoryCheckBox = ctk.CTkCheckBox(self.BagMaterialsFrame, 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)
...
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)) + " €"))
希望你能明白我在做什么哈哈。 我想我无缘无故地把它复杂化了,应该有更简单的方法。