Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

TypeError when trying to read a string entered in a graphical user interface and convert it to an expression

Hi!

I am trying to read a string entered by a user in a GUI constructed with tkinter, and convert this string to a function. However, Sage rises a TypeError when I do this. A minimal example follows.

import tkinter

def compute_phaser_polynomials():
    var('omega')

    str_GroupDelaySpec = entry1.get() # string with the expression of the group delay as a function of omega
    #str_GroupDelaySpec = 'omega + 5/2'
    print(str_GroupDelaySpec)
    print(type(str_GroupDelaySpec))

    gds.<omega> = QQ[]
    group_delay_spec(omega) = gds(str_GroupDelaySpec)
    print(group_delay_spec(omega))
    print(type(group_delay_spec(omega)))

root = tkinter.Tk()

entry1 = tkinter.Entry(root)
entry1.grid()

button1 = tkinter.Button(root, text="Compute phaser polynomials", command=compute_phaser_polynomials)
button1.grid(row=1)

root.mainloop()

When tkinter is not involved, the conversion works.

gds.<omega> = QQ[]
f(omega) = gds('omega + 5/2')
print(f(omega))
print(f(omega).parent())
print(type(f(omega)))

Out: omega + 5/2
Out: Symbolic Ring
Out: <type 'sage.symbolic.expression.Expression'>

Am I doing something wrong? Is this a bug?

Thanks!