from tkinter import * 这是两个列表,其中包含价格和产品详细信息。
price_audible = ['$1.99', '$1.50', '$1.00', '$1.99', '$1.50', '$1.00', '$1.99', '$1.50', '$1.00', '$1.99']
description_audible = ['1: Aaaaaa', '2: bbbbbb', '3: ccccccccc', '4: dddddddddd', '5:eeeeeeee',
'6: fffffff', '7: gggggggg', '8: hhhh', '9: ii', '10: jjjjjjjjjjjjjjjjj']
audible_newlist = ''
for m in range(0, 10):
'\n'
var_1=('#'+description_audible[m])+ '\n' +('('+price_audible[m]+')')+'\n'
audible_newlist = audible_newlist + var_1
show_window = audible_newlist
dash_1 = Tk()
dash_1.configure(bg = 'red')
dash_1.title("Amazon Bestsellers Audible")
show_window = StringVar()
show_window.set(audible_newlist)
conction = IntVar()
def audible_catagory():
new_pc = Toplevel(dash_1)
new_pc.title('Amazon Bestsellers PC')
Label(new_pc, text = "Amazon Bestsellers PC", font = ('Arial', 14),
bg='red', fg='floralwhite').pack()
Label(new_pc, textvariable = show_window, justify = LEFT, bg= 'light yellow',takefocus = True).pack()
Label(dash_1, text = "Amazon Bestsellers Audible", font = ('Arial', 14), bg='red', fg='floralwhite').pack()
Label(dash_1, text = show_window).pack()
Button(dash_1, text = 'Add to cart').pack()
Radiobutton(dash_1, text = 'Amazon Audible', value = True, variable = conction, command =audible_catagory).place(x=0, y=0)
spin_box = Spinbox(dash_1, from_=0, to=10, fg = 'black',
width = 2, justify = RIGHT, relief = 'flat', bg = 'red').pack()
dash_1.mainloop()当你运行这段python代码时,它创建了一个窗口,其中有一个单选按钮,当那个单选按钮点击时,它会弹出另一个窗口,其中显示了商品的价格及其名称,从1到10个商品。有一个旋转框,当它的值从1到10。还有一个按钮,称为添加到购物车。如何将此微调框连接到其余代码和“添加到购物车”按钮。因此,当有人想要购买九号商品时,他们将使用旋转框来选择九号商品,然后当他们按下添加到购物车按钮时,商品将被添加到列表中。它将显示项目的总成本。
如果有人能帮上忙,我将不胜感激。
发布于 2018-05-27 15:13:01
因此,当您单击Add to Cart按钮时,程序应该首先获取Spinbox的值,然后使用该数据从列表中获取商品的价格,并将其价格添加到另一个变量中。
您可以使用spin_box.get()从Spinbox中获取值。要在单击时运行函数,请将属性command=your_function添加到Button(dash_1, text = 'Add to cart').pack()。然后,您可以添加函数:
def your_function():
item_number = spinbox.get()
audible_cart_total_price += price_audible[item_number]注意:您必须将price_audible中的数据更改为数字,而不是字符串。在屏幕上显示时,可以使用字符串插值将美元符号添加回来。
https://stackoverflow.com/questions/50549363
复制相似问题