Is it possible to enlarge the text in window two?

0

I made a calculator in python that opens in a window using the library of the same name. Is there any way that the text shown is bigger?

This is my code:

#!/usr/bin/env python3

from math import *
import os
import time
import sys

salir = False

def input_str(msg="ingrese una operacion:"):
  while True:
        os.system('cls')
        cadena = input(msg)
        try:
           valor = str(cadena)
           if valor in ['a','b','c','d','e','f','g','A','B','C','D','E','F','G']:
               return valor
               break  
        except ValueError:
               continue


def input_float(msg="Ingrese un número:"):
  """Valida que el input ingresado por el usuario sea un float 
     sino vuelve a solictar el ingreso"""

     while True:    
           os.system('cls')
           cadena = input(msg)
           try:
              valor = float(cadena) 
           except ValueError:
               continue
           else:
               return valor
               break

while not salir:

      numero_uno = input_float("introduce un número:")
      os.system('cls')
      operacion = input_str("\n\n'A' para realizar una suma(ejemplo: 9 + 6 = 15)\n\n'B' para realizar una resta(ejemplo: 7 - 3 = 4)\n\n'C' para realizar una multiplicación(ejemplo: 5 * 6 = 30)\n\n'D' para realizar una división 'normal'(ejemplo: 9 / 5 = 1.8)\n\n'E' para obtener el cociente(entero) de la división(ejemplo: 9 // 5 = 1)\n\n'F' para obtener solo el resto de una división(ejemplo: 9 % 5 = 4)\n\n'G' para elevar a una potencia(ejemplo: 3 ** 3 = 27)\n\nintroduce la operación a realizar:")
      os.system('cls')
      numero_dos = input_float("introduce otro número:")
      os.system('cls')

      if operacion == operacion.lower():
          if operacion == 'a':
              print(numero_uno + numero_dos)

          elif operacion == 'b':
              print(numero_uno - numero_dos)

          elif operacion == 'c':
              print(numero_uno * numero_dos)

          elif operacion == 'd':
              print(numero_uno / numero_dos)

          elif operacion == 'e':
              print(numero_uno // numero_dos)

          elif operacion == 'f':
              print(numero_uno % numero_dos)

          elif operacion == 'g':
              print(numero_uno ** numero_dos)


      elif operacion == operacion.upper():
            if operacion == 'A':
                print(numero_uno + numero_dos)

            elif operacion == 'B':
                print(numero_uno - numero_dos)

            elif operacion == 'C':
                print(numero_uno * numero_dos)

            elif operacion == 'D':
                print(numero_uno / numero_dos)

            elif operacion == 'E':
                print(numero_uno // numero_dos)

            elif operacion == 'F':
                print(numero_uno % numero_dos)

            elif operacion == 'G':
                print(numero_uno ** numero_dos)                    

        input()
        os.system('cls')
        reinicio = False
        while not reinicio:
              os.system('cls')
              reiniciar = input("desea realizar otra operación? si/no: ")
              respuesta = reiniciar.lower()
              if respuesta in ["si","no"]:
                  if respuesta == "si":
                     os.system('cls')
                     reinicio = True
                  elif respuesta == "no":
                       reinicio = True
                       salir = True

    
asked by ElAlien123 06.01.2018 в 06:22
source

1 answer

0

One way is to play directly with the windows API, there are many examples on the network, I will adapt a bit this Answer:

import ctypes

FW_DONTCARE       = 0
LF_FACESIZE       = 32
STD_OUTPUT_HANDLE = -11

class COORD(ctypes.Structure):
    _fields_ = [("X", ctypes.c_short), ("Y", ctypes.c_short)]

class CONSOLE_FONT_INFOEX(ctypes.Structure):
    _fields_ = [("cbSize", ctypes.c_ulong),
                ("nFont", ctypes.c_ulong),
                ("dwFontSize", COORD),
                ("FontFamily", ctypes.c_uint),
                ("FontWeight", ctypes.c_uint),
                ("FaceName", ctypes.c_wchar * LF_FACESIZE)]


def set_console_font(font_name="Lucida Console", size=11):
    font = CONSOLE_FONT_INFOEX()
    font.cbSize = ctypes.sizeof(CONSOLE_FONT_INFOEX)
    font.nFont = 0
    font.dwFontSize.X = size
    font.dwFontSize.Y = FW_DONTCARE
    font.FontFamily = FW_DONTCARE
    font.FontWeight = 400
    font.FaceName = font_name

    handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
    ctypes.windll.kernel32.SetCurrentConsoleFontEx(
            handle, ctypes.c_long(False), ctypes.pointer(font))

set_console_font("Lucida Console", 10)

Basically we are invoking the API SetCurrentConsoleFontEx that exactly configures the font to use in the console, for that we need to define the structures COORD and CONSOLE_FONT_INFOEX , we rely on the module ctypes for all the specific to the Win api. In this example, we simply invoke set_console_font() that receives two parameters, the FONT and the size. Keep in mind that:

  • The configuration is from the console, when you exit your program it will remain. It could recover the previous configuration but it is subject for another question.
  • This solution is obviously only for console-type applications in Windows.
  • The allowed fonts are fixed size.
answered by 07.01.2018 / 17:52
source