0

Anglais

I would like to calculate by retrieving data in a textbox but it gives me an error:

Traceback (most recent call last):
  File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 43, in <module>
    exe_button = Button(height=1, width=20, text='Exécuter', command=Calc())
  File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 15, in Calc
    result = text_label_1.get * text_label_2
TypeError: unsupported operand type(s) for *: 'method' and 'Text'

Process finished with exit code 1

And the code is :

import tkinter
from tkinter import *
from tkinter import Text

help(tkinter.Text.get)

window = Tk()

window.minsize(1200, 400)

def Calc():
    result = text_label_1.get * text_label_2
    print(str(result))


text_label_1: Text = Text(window, height=1, width=10)
text_label_1.grid(row=0, column=2)

text_label_2 = Text(window, height=1, width=10)
text_label_2.grid(row=0, column=4)

name_label_1 = Label(window, height=1, width=10, text='Tension')
name_label_1.grid(row=0, column=0)

name_label_2 = Label(window, height=1, width=10, text=' = ')
name_label_2.grid(row=0, column=1)

name_label_3 = Label(window, height=1, width=10, text=' * ')
name_label_3.grid(row=0, column=3)

name_label_4 = Label(window, height=1, width=10, text=' = ')
name_label_4.grid(row=0, column=5)

name_label_5 = Label(window, height=1, width=10)
name_label_5.grid(row=0, column=6)

exe_button = Button(height=1, width=20, text='Exécuter', command=Calc())
exe_button.grid(row=1, column=5)

window.mainloop()

Ok but what is the index1 ? 




    Traceback (most recent call last):
  File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 47, in <module>
    exe_button = Button(height=1, width=20, text='Exécuter', command=Calc())
  File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 17, in Calc
    r = int(text_label_1.get())
TypeError: get() missing 1 required positional argument: 'index1'
Makyen
  • 31,849
  • 12
  • 86
  • 121

1 Answers1

0

text_label_1.get * text_label_2 - the issue is that text_label_1.get is a method (function) while text_label_2 is a Text. You need to get the text from both labels, convert to numbers and do the math

balderman
  • 22,927
  • 7
  • 34
  • 52