pythontkinterterminalprintingsympy

Is there any way to print the expressions of sympy pretty in pydroid3


Two questions, the first question, is it possible to print expressions of sympy In an attractive way in the terminal of pydroid3 Especially in pydroid3 terminal because most of the ways like below has no effect at all.

init_printing(use_unicode=True)

The second question, in tkinter ui system or in tkinter ui in general, how to display those expressions as Label or anything similar, if not possible is there any other GUI library This is possible in it.


import sympy as sy

x, y, z = sy.symbols("x y z")

sy.init_printing(use_unicode=True) # not working

print(x*sy.sqrt(y))

print(z*sy.cos(x))

print(sy.Matrix([[1, 2], [3, 5], [x,y]]))


I really hope I asked correctly.


Solution

  • You can use SymPy's ppprint to print as a pretty string orpretty to get the string:

    In [2]: e = sqrt(x*y**2)
    
    In [3]: pprint(e)
       ______
      ╱    2 
    ╲╱  x⋅y  
    
    In [4]: s = pretty(e)
    
    In [5]: s
    Out[5]: '   ______\n  ╱    2 \n╲╱  x⋅y  '
    
    In [6]: print(s)
       ______
      ╱    2 
    ╲╱  x⋅y