为什么程序没有使用代码中列出的信息?

时间:2018-02-10 12:23:01

标签: python tkinter

from tkinter import*
from tkinter import Tk, StringVar, ttk
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
import random
import datetime
import time;
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
start = Tk()
start.geometry("100x600+0+0")
start.title ("R.E.D Inventory Control System")


#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
Heading = Frame(start, width = 1000, height = 100, bd = 10, relief = 'raise')
Heading.pack(side = TOP)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
LowerHeading = Frame(start, width = 500, height  = 100, bd = 20, relief = 'raise')
LowerHeading.pack(side = BOTTOM)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
LMiddle = Frame(start, width = 500, height = 1000, bd = 12, relief = 'raise')
LMiddle.pack(side = LEFT)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
RMiddle = Frame(start, width = 500, height = 1000, bd = 12, relief = 'raise')
RMiddle.pack(side=RIGHT)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
Title = Label(Heading, font=('arial',40,'bold'), text = "R.E.D Inventory Control System", bd = 10, width = 40, anchor = 'w')
          #justify = 'center')
Title.grid(row=0,column=0)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
info1=IntVar()
info2=StringVar()


info1.set("0")
info2.set("")
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
def Product():
    if (info1.get()=="ID01"):
        info2.set("Dress")


#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
ProductID = Label(LMiddle, font=('arial',12,'bold'),text = "Product ID", bd = 10, width = 15, anchor = 'w')
ProductID.grid(row=0,column=0)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
ProductsID = ttk.Combobox(LMiddle, variable = info1 ,state='readonly', font=('arial',12,'bold'),  width =20)
ProductsID['value']=('','ID01','ID02','ID03','ID04','ID05')
ProductsID.current(0)
ProductsID.grid(row=0,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
Description1 = Label(LMiddle, font=('arial',12,'bold'),text ="Description", bd = 10, width = 15, anchor = 'w')
Description1.grid(row=2,column=0)
Description2 = Label(LMiddle, font=('arial',12,'bold'), variable = info2, bd = 10, width = 18, relief = 'sunken')
Description2.grid(row=2,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
DateStockBought1 = Label(LMiddle, font=('arial',12,'bold'), text ="Date Stock Bought", bd = 10, width = 15, anchor = 'w')
DateStockBought1.grid(row=3,column=0)
DateStockBought2 = Label(LMiddle, font=('arial',12,'bold'), bd = 10, width = 18, relief = 'sunken')
DateStockBought2.grid(row=3,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
Price1 = Label(LMiddle, font=('arial',12,'bold'), text ="Price", bd = 10, width = 15, anchor = 'w')
Price1.grid(row=4,column=0)
Price2 = Label(LMiddle, font=('arial',12,'bold'), bd = 10, width = 18, relief = 'sunken')
Price2.grid(row=4,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
AmountLeft1 = Label(RMiddle, font=('arial',12,'bold'), text ="Amount Left", bd = 10, width = 15, anchor = 'w')
AmountLeft1.grid(row=1,column=0)
AmountLeft2 = Label(RMiddle, font=('arial',12,'bold'), bd = 10, width = 18,     relief = 'sunken')
AmountLeft2.grid(row=1,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
CurrentSeason1 = Label(RMiddle, font=('arial',12,'bold'), text ="CurrentSeason", bd = 10, width = 15, anchor = 'w')
CurrentSeason1.grid(row=2,column=0)
CurrentSeason2 = Label(RMiddle, font=('arial',12,'bold'), text = "", bd = 10, width = 18, relief = 'sunken')
CurrentSeason2.grid(row=2,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
Discount1 = Label(RMiddle, font=('arial',12,'bold'), text ="Discount", bd = 10, width = 15, anchor = 'w')
Discount1.grid(row=3,column=0)
Discount2 = Label(RMiddle, font=('arial',12,'bold'), bd = 10, width = 18, relief = 'sunken')
Discount2.grid(row=3,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
NewPrice1 = Label(RMiddle, font=('arial',12,'bold'), text ="New Price", bd = 10, width = 15, anchor = 'w')
NewPrice1.grid(row=4,column=0)
NewPrice2 = Label(RMiddle, font=('arial',12,'bold'), bd = 10, width = 18, relief = 'sunken')
NewPrice2.grid(row=4,column=1)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#

start.mainloop()

因此,上述代码应该是一个库存管理系统,它使用代码中的数据,允许经理根据产品的季节和当前的季节来改变价格。到目前为止,我已经收到了无法做到的错误。

以下是:

Traceback (most recent call last):
    File "C:\Users\****\Documents\****\****\****\****\Inventory (new).py", line 46, in <module>
    ProductsID = ttk.Combobox(LMiddle, variable = info1 ,state='readonly', font=('arial',12,'bold'),  width =20)
  File "C:\Python34\lib\tkinter\ttk.py", line 703, in __init__
Entry.__init__(self, master, "ttk::combobox", **kw)
  File "C:\Python34\lib\tkinter\ttk.py", line 665, in __init__
Widget.__init__(self, master, widget or "ttk::entry", kw)
  File "C:\Python34\lib\tkinter\ttk.py", line 553, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
  File "C:\Python34\lib\tkinter\__init__.py", line 2122, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-variable"

我将不胜感激任何帮助

1 个答案:

答案 0 :(得分:1)

替换:

info1=IntVar()
...
ProductsID = ttk.Combobox(..., variable = info1, ...
...
Description2 = Label(..., variable = info2, ...

使用:

info1 = StringVar()
...
ProductsID = ttk.Combobox(..., textvariable = info1, ...
...
Description2 = Label(..., textvariable = info2, ...

当您将字符串value用于ProductsID时,它取而代之的是textvariable选项,而不是variable选项(因为Combobox }实际上是Entry)的子类。类似的内容适用于Label对象Description2