1

How can I display an editable fraction in a Tkinter Text box? Like in Word or another text editor. I'm making a function to insert equations in a Tkinter Text box.

screenshot of fraction

Ethan Chan
  • 153
  • 11
  • 1
    You can create fractions using Unicode superscript & subscript (digit) characters which tkinter can display if the proper font it used (i.e. one that contains them). For example: ¹³⁄₄₂ – martineau Jul 18 '22 at 16:34
  • 1
    Could I make it look like Symbolab's fractions? https://www.symbolab.com/solver/algebra-calculator – Ethan Chan Jul 18 '22 at 16:36
  • 2
    If you want to have perfectly horizontal fraction bar, you would probably have to draw it yourself, which would preclude using a `Text` widget (i.e. you would need to use a `Canvas` widget and "draw" what you want displayed onto it). – martineau Jul 18 '22 at 16:42
  • 3
    It's probably easier to separate the entry from the rendering: the user input "3/4" in an `Entry`, press some "insert" button and you render the fraction in a `Canvas`. – j_4321 Jul 19 '22 at 08:18
  • It is possible to put images in a `Text` widget via its `.image_create()` method — so you could render the fractions into a small bitmap and put that in. Here's some [documentation](https://tkdocs.com/shipman/text-methods.html) on it. However I am unsure exactly how the user interface would work, but you can also "tag" things (characters and images) in a Text widget and "bind" event handlers that will be called when they are selected — so maybe an approach based on that would be feasible. – martineau Jul 21 '22 at 02:46

0 Answers0