【发布时间】:2018-06-10 13:07:44
【问题描述】:
所以我一直在做一个项目,最近遇到了我的检查按钮问题。每当我尝试做variablenname.get() 时,它永远不会像int value has no attribute get() 所说的那样工作。我也确实使用了variablename = IntVar(),我想做的是根据检查按钮的值制作 if 语句。
var = IntVar()
BTR = Tk()
Discounts = Checkbutton(BTR, text="Discount (Students, Under 18s, 65+ and Disability Badge Holders)", font = ("times", 30), bg="#252538", fg = "#99FFFF", variable = var)
Discounts.place(x=120, y=300)
PriceTag=Label(BTR, text =("£", Cost), font = ("times", 50), fg = "White", bg = "#252538")
PriceTag.place(x=1000, y= 450)
val=Label(BTR, text = Tickets, font = ("times", 22), height = 5, width = 15, bg= "White")
val.place(x=175, y=550)
add=Button(BTR, text = "+", font = ("times", 22), height = 5, width = 10, bg = "#B266FF", command = lambda: UpdateAdd(val, BTR, PriceTag, BusTicketPrice, price, var))
add.place(x=420, y=550)
def UpdateAdd(val, BTR, PriceTag, BusTicketPrice, price, var):
var = var.get()
Tickets = Tickets + 1
val.destroy()
val = Label(BTR, text = Tickets, font = ("times", 22), height = 5, width = 15, bg= "White")
val.place(x=175, y=550)
PriceTag.destroy()
if price == "Peak" and var == 0 :
BusTicketPrice=BusTicketPrice*1.25
elif var == 1 and price == "Peak":
BusTicketPrice=BusTicketPrice
elif var == 1 and price == "Off-Peak":
BusTicketPrice=BusTicketPrice*0.75
elif price == "Off-Peak" and var == 0):
BusTicketPrice=BusTicketPrice
Cost = BusTicketPrice * Tickets
Cost = round(Cost, 3)
PriceTag=Label(BTR, text =("£", str(Cost), "0"), font = ("times", 50), fg = "White", bg = "#252538")
PriceTag.place(x=1000, y= 450)
【问题讨论】:
-
变量值使用.get()
-
您能否编辑您的代码以仅显示与您的问题相关的代码
-
我已将根窗口分配给我的程序的主屏幕,以在我的程序的标签中插入图片,我编辑了删除不必要部分的代码,但问题仍然是变量有不是 get() 的属性
-
我的回答解释了为什么
UpdateAdd中的var不再具有.get属性。感谢您编辑您的代码,但它仍然无法运行。请阅读有关制作minimal reproducible example 的信息。