Whenever we are working with formulas there may be a need of writing the given formula in a given format which may require subscripts or superscripts. There are several methods available to print subscripts and superscripts in Python. We will be discussing two of them below – Using maketrans() and translate() : We can make two strings one for the normal characters and the other for the subscript/superscript characters. After this, we can use the maketrans() method which returns a mapping that can be used with the translate() method to replace the specified characters. It can be implemented for superscripts as Python3
H₂SO₄1 = H₂SO₄3
H₂SO₄5 = H₂SO₄7 H₂SO₄8 H₂SO₄9
H₂SO₄ x² + y² = 21 H₂SO₄ x² + y² = 22 H₂SO₄ x² + y² = 23 H₂SO₄ x² + y² = 24 H₂SO₄ x² + y² = 25 H₂SO₄ x² + y² = 26 H₂SO₄ x² + y² = 27 H₂SO₄ x² + y² = 28 H₂SO₄ x² + y² = 29 Output: ᴳᵉᵉᵏˢᶠᵒʳᴳᵉᵉᵏˢ And for subscripts, we can implement it as Python3
H₂SO₄5 = H₂SO₄7 H₂SO₄8 def 6
H₂SO₄ x² + y² = 21 H₂SO₄ x² + y² = 22 H₂SO₄ x² + y² = 23
H₂SO₄ x² + y² = 25 get_super(x): 3get_super(x): 4get_super(x): 5get_super(x): 6get_super(x): 7get_super(x): 8get_super(x): 9 0 1 2 Python provides a variety of GUI (Graphic User Interface) types such as PyQT, Tkinter, Kivy, WxPython, and PySide. Among them, Note: Tkinter(capital T) is different from the tkinter. Tkinter is used in Python2.x and is changed to tkinter in Python.3x. Combobox is a combination of Listbox and an entry field. It is one of the Tkinter widgets where it contains a down arrow to select from a list of options. It helps the users to select according to the list of options displayed. When the user clicks on the drop-down arrow on the entry field, a pop up of the scrolled Listbox is displayed down the entry field. The selected option will be displayed in the entry field only when an option from the Listbox is selected. Syntax: combobox = ttk.Combobox(master, option=value, ...) Example 1: Combobox widget without setting a default value.
Output: Example 2: Combobox with initial default values.
|