Python / Tinker 관련 문제 : TypeError : 지원되지 않는 피연산자 유형

LoudEye

Python과 Tkinter를 사용하여 피트 당 볼륨 계산기를 구축하려고합니다. 이 오류 메시지가 계속 표시됩니다. 나는 그것이 아마도 내가 간과하고있는 단순한 것임을 압니다. 아무도 내가 어디로 잘못 가고 있는지 볼 수 있습니까? 미리 감사드립니다.

이것은 내 코드입니다.

from tkinter import *

root = Tk()
root.title("Volume Calculator")

def volume_per_foot():
    gallons_per_foot = inside_diameter * inside_diameter / 1029.4
    return (gallons_per_foot)

frame = LabelFrame(root, text="BHA", padx=5, pady=5)
frame.grid(padx=10, pady=10)

component_label = Label(frame, text="Component")
component_label.grid(row=0)
component = Entry(frame)
component.grid(row=1)

component_length = Label(frame, text="Length")
component_length.grid(row=2)
length = Entry(frame)
length.grid(row=3)

component_outside_diameter = Label(frame, text="Outside Diameter")
component_outside_diameter.grid(row=4)
outside_diameter = Entry(frame)
outside_diameter.grid(row=5)

component_inside_diameter = Label(frame, text="Inside Diameter")
component_inside_diameter.grid(row=6)
inside_diameter = Entry(frame)
inside_diameter.grid(row=7)

submit = Button(frame, text="Enter", command=volume_per_foot)
submit.grid(row=8)

gal_per_foot = Label(frame, text="Gallons Per Foot")
gal_per_foot.grid(row=9)
component_volume = Label(frame)
component_volume.grid(row=10)

root.mainloop()

그리고 이것은 오류 메시지입니다.

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
    return self.func(*args)
  File "volume.py", line 34, in volume_per_foot
    gallons_per_foot = inside_diameter * inside_diameter / 1029.4
TypeError: unsupported operand type(s) for *: 'Entry' and 'Entry'
스테판 셸러

Tk 객체에서 값을 가져 와서 다음 Entry과 같은 숫자로 변환해야합니다.

gallons_per_foot = float(inside_diameter.get()) * float(inside_diameter.get()) / 1029.4

최신 정보

버튼 콜백에서 반환 값을 얻을 수 없습니다. 결과를 레이블에 표시하려면 다음을 수행 할 수 있습니다.를 도입 StringVar하고 레이블에 바인딩하고 단추 콜백에 전달하고 (여기서는 클로저와 람다 함수를 사용하고 있습니다) 계산 후 해당 값을 변경합니다.

def volume_per_foot(result_text):
    gallons_per_foot = float(inside_diameter.get()) * float(inside_diameter.get()) / 1029.4
    result_text.set(str(gallons_per_foot))
result_text = StringVar()
result_text.set("Gallons Per Foot")

submit = Button(frame, text="Enter", command=lambda *args:volume_per_foot(result_text))
submit.grid(row=8)

gal_per_foot = Label(frame, textvariable=result_text)
gal_per_foot.grid(row=9)

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

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

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

TypeError : Python에서 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : Python에서 지원되지 않는 피연산자 유형

분류에서Dev

Python : TypeError : + : 'NoneType'및 'int'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

Python 2.7 TypeError : % : 'None type'및 str에 지원되지 않는 피연산자 유형

분류에서Dev

Python 3 TypeError : ** 또는 pow ()에 대해 지원되지 않는 피연산자 유형 : 'str'및 'int'

분류에서Dev

Python에서 지원되지 않는 피연산자 유형

분류에서Dev

Python 유형 오류 지원되지 않는 피연산자

분류에서Dev

Python (TypeError : 추가에 대해 지원되지 않는 피연산자 유형 : 'undefined'및 'str')

분류에서Dev

Python3 : socket : TypeError : % : 'bytes'및 'bytes'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : Python 3에서 + = : 'float'및 'NoneType'에 지원되지 않는 피연산자 유형

분류에서Dev

TypeError :-에 대해 지원되지 않는 피연산자 유형 : 'Position'및 'Position'

분류에서Dev

TypeError :-: 'Approximate'및 'float'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : +에 대해 지원되지 않는 피연산자 유형 : 'NoneType'및 'list'

분류에서Dev

TypeError : + =에 대해 지원되지 않는 피연산자 유형 : 'int'및 'list'with Pygame

분류에서Dev

TypeError : %에 대해 지원되지 않는 피연산자 유형 : 'NoneType'및 'int'

분류에서Dev

TypeError : % : 'Text'및 'tuple'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : | : 'list'및 'list'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : +에 대해 지원되지 않는 피연산자 유형 : 'int'및 'str'값

분류에서Dev

지원되지 않는 피연산자 유형 'int'및 'list'에 대한 TypeError

분류에서Dev

TypeError :-: 'float'및 'method'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

TypeError :-: 'instance'및 'float'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : 'Instance'및 'Int'에 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : 지원되지 않는 피연산자 유형 % : 'NoneType'및 'tuple'with random generator?

분류에서Dev

+ : 'dict'및 'int'에 대해 Django TypeError 지원되지 않는 피연산자 유형

분류에서Dev

TypeError :-: 'tuple'및 'tuple'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : div에 지원되지 않는 피연산자 유형 : 'str'및 'int'[14 행]

분류에서Dev

TypeError : + = : 'int'및 'str'에 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : << : 'int'및 'float'에 지원되지 않는 피연산자 유형

분류에서Dev

TypeError : + : 'Timestamp'및 'float'에 대해 지원되지 않는 피연산자 유형

Related 관련 기사

  1. 1

    TypeError : Python에서 지원되지 않는 피연산자 유형

  2. 2

    TypeError : Python에서 지원되지 않는 피연산자 유형

  3. 3

    Python : TypeError : + : 'NoneType'및 'int'에 대해 지원되지 않는 피연산자 유형

  4. 4

    Python 2.7 TypeError : % : 'None type'및 str에 지원되지 않는 피연산자 유형

  5. 5

    Python 3 TypeError : ** 또는 pow ()에 대해 지원되지 않는 피연산자 유형 : 'str'및 'int'

  6. 6

    Python에서 지원되지 않는 피연산자 유형

  7. 7

    Python 유형 오류 지원되지 않는 피연산자

  8. 8

    Python (TypeError : 추가에 대해 지원되지 않는 피연산자 유형 : 'undefined'및 'str')

  9. 9

    Python3 : socket : TypeError : % : 'bytes'및 'bytes'에 대해 지원되지 않는 피연산자 유형

  10. 10

    TypeError : Python 3에서 + = : 'float'및 'NoneType'에 지원되지 않는 피연산자 유형

  11. 11

    TypeError :-에 대해 지원되지 않는 피연산자 유형 : 'Position'및 'Position'

  12. 12

    TypeError :-: 'Approximate'및 'float'에 대해 지원되지 않는 피연산자 유형

  13. 13

    TypeError : +에 대해 지원되지 않는 피연산자 유형 : 'NoneType'및 'list'

  14. 14

    TypeError : + =에 대해 지원되지 않는 피연산자 유형 : 'int'및 'list'with Pygame

  15. 15

    TypeError : %에 대해 지원되지 않는 피연산자 유형 : 'NoneType'및 'int'

  16. 16

    TypeError : % : 'Text'및 'tuple'에 대해 지원되지 않는 피연산자 유형

  17. 17

    TypeError : | : 'list'및 'list'에 대해 지원되지 않는 피연산자 유형

  18. 18

    TypeError : +에 대해 지원되지 않는 피연산자 유형 : 'int'및 'str'값

  19. 19

    지원되지 않는 피연산자 유형 'int'및 'list'에 대한 TypeError

  20. 20

    TypeError :-: 'float'및 'method'에 대해 지원되지 않는 피연산자 유형

  21. 21

    TypeError :-: 'instance'및 'float'에 대해 지원되지 않는 피연산자 유형

  22. 22

    TypeError : 'Instance'및 'Int'에 지원되지 않는 피연산자 유형

  23. 23

    TypeError : 지원되지 않는 피연산자 유형 % : 'NoneType'및 'tuple'with random generator?

  24. 24

    + : 'dict'및 'int'에 대해 Django TypeError 지원되지 않는 피연산자 유형

  25. 25

    TypeError :-: 'tuple'및 'tuple'에 대해 지원되지 않는 피연산자 유형

  26. 26

    TypeError : div에 지원되지 않는 피연산자 유형 : 'str'및 'int'[14 행]

  27. 27

    TypeError : + = : 'int'및 'str'에 지원되지 않는 피연산자 유형

  28. 28

    TypeError : << : 'int'및 'float'에 지원되지 않는 피연산자 유형

  29. 29

    TypeError : + : 'Timestamp'및 'float'에 대해 지원되지 않는 피연산자 유형

뜨겁다태그

보관