0
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()

So, the above code is supposed to be a stock management system that uses data within the code to allow the manager to change prices based on what season the product is and what season it is currently. So far i have recieved the error that this cannot be done.

It is the following:

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"

I would appreciate any help

E.M
  • 11
  • 4

1 Answers1

1

Replace:

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

with:

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

As you're using strings as values to ProductsID and that it instead has textvariable option as opposed to variable option(as Combobox is actually a subclass to Entry). Something similar applies for the Label object, Description2.

Nae
  • 14,209
  • 7
  • 52
  • 79
  • Thanks so much, That sorted out the error. But do you know why it isn't changing Description? As when i press ID01 on the GUI, the description box should change to Dress but it doesn't??? – E.M Feb 10 '18 at 13:03
  • @E.M Because `Product` is not necessarily called when a selection occurs. See [`postcommand`](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Combobox.html) option here for calling a method in between clicking an item and making it the selection(which is oddly inconvenient) or [`trace`](http://effbot.org/tkinterbook/variable.htm)(actually this is deprecated you should be using `trace_all` instead) here for calling a method when the value the Variable class holds(`StringVar` for ex.) is modified. – Nae Feb 10 '18 at 13:10
  • 1
    @Nae: `postcommand` isn't designed to be called when the value changes. It is designed to give you a chance to dynamically update the menu before it is shown. It's extremely convenient when used for that purpose. – Bryan Oakley Feb 10 '18 at 13:41
  • @E.M See [this question & answers](https://stackoverflow.com/q/48723444/7032856). – Nae Feb 10 '18 at 17:17
  • @Nae I'm not sure how to do it. Could you please give me an example? – E.M Feb 11 '18 at 13:11
  • @BryanOakley I would appreciate your help too – E.M Feb 11 '18 at 13:12
  • @E.M There _are_ examples given in the link. – Nae Feb 11 '18 at 19:31