이 오류에 대한 수정 ---> TypeError : 'StringVar'개체를 호출 할 수 없습니다.

윌리엄 제퍼슨

이 GUI 계산기를 만들려고하는데 'StringVar'개체를 호출 할 수없는 것 같습니다. 문제는-, *, /, = 등과 같은 다른 연산자에서도 지속됩니다. (저는 코딩과 파이썬의 세계에 신선합니다),

tkinter에서 import Tk, Label, StringVar, Entry, Button, W, E

클래스 계산기 : 피연산자 : StringVar 연산자 : 없음 결과 : float

def __init__(self):
    master = Tk()        
    self.operator = None
    self.operand = StringVar()
    self.result = 0
    
         
    Label(master,text = "Calculator").grid(row = 0, column=0, columnspan=2)
    
    UserInputEntry = master.register(self.operandValid)
    Entry(master, validate="key", validatecommand=(UserInputEntry,'%P'), textvariable=self.operand).grid(row=0, column=0, columnspan=3)
                                     
    addAction = lambda: self.operand(lambda a, b: a+b)
    Button(master,text = "+",command=addAction).grid(row=1, column=3, sticky=W+E)
    
    subAction = lambda: self.operand(lambda a, b: a-b)
    Button(master,text = "-",command=subAction).grid(row=2, column=3, sticky=W+E)
    
    mulAction = lambda: self.operand(lambda a, b: a*b)
    Button(master,text = "X",command=mulAction).grid(row=3, column=3, sticky=W+E)
    
    divAction = lambda: self.operand(lambda a, b: a/b)
    Button(master,text = "/",command=divAction).grid(row=4, column=3, sticky=W+E)
    
    equal = lambda: self.operand(None)
    Button(master,text = "=",command=equal).grid(row=4, column=2, sticky=W+E)       
    
    enter1 = lambda: self.enterNumber("1")
    Button(master,text = "1",command=enter1).grid(row=1, column=0, sticky=W+E)
    
    
    enter2 = lambda: self.enterNumber("2")
    Button(master,text = "2",command=enter2).grid(row=1, column=1, sticky=W+E)
    
    enter3 = lambda: self.enterNumber("3")
    Button(master,text = "3",command=enter3).grid(row=1, column=2, sticky=W+E)
    
    
    enter4 = lambda: self.enterNumber("4")
    Button(master,text = "4",command=enter4).grid(row=2, column=0, sticky=W+E)
    
    enter5 = lambda: self.enterNumber("5")
    Button(master,text = "5",command=enter5).grid(row=2, column=1, sticky=W+E)
    
    enter6 = lambda: self.enterNumber("6")
    Button(master,text = "6",command=enter6).grid(row=2, column=2, sticky=W+E)
    
    enter7 = lambda: self.enterNumber("7")
    Button(master,text = "7",command=enter7).grid(row=3, column=0, sticky=W+E)
    
    enter8 = lambda: self.enterNumber("8")
    Button(master,text = "8",command=enter8).grid(row=3, column=1, sticky=W+E)
    
    enter9 = lambda: self.enterNumber("9")
    Button(master,text = "9",command=enter9).grid(row=3, column=2, sticky=W+E)
    
    enter0 = lambda: self.enterNumber("0")
    Button(master,text = "0", command=enter0).grid(row=4, column=0, sticky=W+E)
    
    enterDecimal = lambda: self.enterNumber(".")
    Button(master,text=".",command=enterDecimal).grid(row=4, column=1, sticky=W+E)
    
    master.mainloop()
    
    
def operation(self, op):
    print("The previous operation was {self.operation}")
    self.result = self.operator(self.result, float(self.operand))
    self.operator = op

def operandValid(self, operand):
    try: 
        operand = float(operand)
        return True
    except:
        return False
def enterNumber(self,character): 
            
    #if self.resultDisplayed: 
        #self.resultDisplayed = False
        #self.operand.set("")#reset the Entry for new input
    
    if(self.operandValid(self.operand.get()+character)):
        self.operand.set(self.operand.get()+character)

계산자()

addAction = lambda : self.operand (lambda a, b : a + b) TypeError : 'StringVar'object is not callable

그것은 당신이 StringVar()(lambda a, b: a+b). 람바다는 안에 self.operand두고 나머지는 그대로두면됩니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

Pytorch 1.7.0 | DataLoader 오류-TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

계산기 오류 : TypeError : 'float'개체를 호출 할 수 없습니다.

분류에서Dev

zip () 함수를 사용할 때 다음 오류를 어떻게 수정할 수 있습니까? TypeError : '목록'개체를 호출 할 수 없습니다.

분류에서Dev

Python 3.x에서 오류 발생 : TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

BeautifulSoup을 사용한 웹 사이트 스크랩 : TypeError : 'NoneType'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 계산을 인쇄 한 후 'float'개체를 호출 할 수 없습니다.

분류에서Dev

'Uncaught TypeError : _.lpad is not a function'오류에 대해 Underscore.String 함수 'lpad'를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

분류에서Dev

TypeError : mongodb에서 '컬렉션'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

분류에서Dev

firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

분류에서Dev

Q : TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Post'개체를 호출 할 수 없습니다.

분류에서Dev

groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

분류에서Dev

Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '게임'개체를 호출 할 수 없습니다.

분류에서Dev

Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

Python-TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Weather'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Aircraft'개체를 호출 할 수 없습니다.

분류에서Dev

Python TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError '모듈'개체를 호출 할 수 없습니다.

Related 관련 기사

  1. 1

    Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

  2. 2

    Pytorch 1.7.0 | DataLoader 오류-TypeError : '모듈'개체를 호출 할 수 없습니다.

  3. 3

    계산기 오류 : TypeError : 'float'개체를 호출 할 수 없습니다.

  4. 4

    zip () 함수를 사용할 때 다음 오류를 어떻게 수정할 수 있습니까? TypeError : '목록'개체를 호출 할 수 없습니다.

  5. 5

    Python 3.x에서 오류 발생 : TypeError : 'int'개체를 호출 할 수 없습니다.

  6. 6

    BeautifulSoup을 사용한 웹 사이트 스크랩 : TypeError : 'NoneType'개체를 호출 할 수 없습니다.

  7. 7

    TypeError : 계산을 인쇄 한 후 'float'개체를 호출 할 수 없습니다.

  8. 8

    'Uncaught TypeError : _.lpad is not a function'오류에 대해 Underscore.String 함수 'lpad'를 호출 할 수 없습니다.

  9. 9

    TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

  10. 10

    TypeError : mongodb에서 '컬렉션'개체를 호출 할 수 없습니다.

  11. 11

    TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

  12. 12

    TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

  13. 13

    TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

  14. 14

    firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

  15. 15

    TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

  16. 16

    TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

  17. 17

    Q : TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

  18. 18

    TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

  19. 19

    TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

  20. 20

    TypeError : 'Post'개체를 호출 할 수 없습니다.

  21. 21

    groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

  22. 22

    Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

  23. 23

    TypeError : '게임'개체를 호출 할 수 없습니다.

  24. 24

    Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

  25. 25

    Python-TypeError : 'list'개체를 호출 할 수 없습니다.

  26. 26

    TypeError : 'Weather'개체를 호출 할 수 없습니다.

  27. 27

    TypeError : 'Aircraft'개체를 호출 할 수 없습니다.

  28. 28

    Python TypeError : '모듈'개체를 호출 할 수 없습니다.

  29. 29

    TypeError '모듈'개체를 호출 할 수 없습니다.

뜨겁다태그

보관