简体   繁体   中英

Python calculations

I am trying to make a program that will display total stock of cement, brick, spanner, mirror, and hammer. But the problem Please help me is thsi program keeps showing me' cementinVar is not defined' but i already defined it above as (cementinVar = Tkinter.IntVar()) .

def textboxvalue2():

    Total_StockIn = 0



    CementIn = cementinVar.get()
    HammerIn = hammerinVar.get()
    SpannerIn = spannerinVar.get()
    BrickIn = brickinVar.get()
    MirrorIn = mirrorinVar.get()

    CementOut = cementoutVar.get()
    HammerOur = hammeroutVar.get()
    SpannerOut = spanneroutVar.get()
    BrickOut = brickoutVar.get()
    MirrorOut = mirroroutVar.get()

    Total_StockIn = (CementIn + HammerIn + SpannerIn + BrickIn + MirrorIn)+Total_StockIn
    StockInLabel = Tkinter.Label(sub,text='The total  stock in is '+str(Total_StockIn))
    StockInLabel.grid(row=7, column =2)

You define cementinVar in another scope. You have two possible solutions:

  1. Use a global variable
  2. Use a class variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM