centrar botones y texto en GUIZERO python
Publicado por lucía (7 intervenciones) el 29/03/2023 19:36:01
Buenas tardes. Necesito centrar el texto y los botones en el centro de la ventana. Lo que tengo ahora mismo en mi programa es esto:
(si le dais a ejecutar os dareis cuenta de cuál es el error, el texto me sale a la izquierda, las cajitas en el centro y el otro botón en la derecha y quiero que esté todo centrado)
from guizero import App, Text, Box, TextBox, PushButton, Picture
# App -----------------------
app = App(bg = "light blue",
title ="GTDM",
height = 550,
width = 650)
app.align = "center"
grid_box = Box(app, layout="grid")
# Functions and variables ---
peso = ""
def get_peso(e):
global peso
input_asked = "peso"
if (e == '\r'):
#tenemos el peso: clear text box and clear list
text_peso.clear()
text_peso.append("Tu peso es: " + peso)
textbox_peso.clear()
peso = ""
elif (e.isdigit()):
peso = peso + e
print(e)
print(peso)
else:
#no es una entrada valida
text_peso.clear()
peso = ""
app.info("error", "no es " + input_asked + " valida")
altura = ""
def get_altura(e):
global altura
input_asked = "altura"
if (e == '\r'):
#tenemos la edad: clear text box and clear list
text_altura.clear()
text_altura.append("Tu altura es: " + altura)
textbox_altura.clear()
altura = ""
elif (e.isdigit()):
altura = altura + e
print(e)
print(altura)
else:
#no es una entrada valida
text_altura.clear()
altura = ""
app.info("error", "no es " + input_asked + " valida")
bmi = 0
def calcular_bmi():
if ((altura != "") and (peso != "")):
global bmi
l = int (altura)
p = int (peso)
bmi = p / ((l/100)**2)
text_bmi.clear()
text_bmi.append("Tu BMI es: " + str('{0:.2f}'.format(bmi)))
if (bmi >= 25.0 and bmi <= 29.9):
tipo_bmi = "Sobrepeso (no obesidad)"
elif (bmi >= 30 and bmi <= 34.9):
tipo_bmi = "Obesidad clase 1 (de bajo riesgo)"
elif (bmi >= 35 and bmi <= 39.9):
tipo_bmi = "Obesidad clase 2 (riesgo moderado)"
elif (bmi >= 40):
tipo_bmi = "Obesidad clase 3 (de alto riesgo)"
else:
app.info("error", "entra peso y altura valida")
# Widgets -----------------------
input_asked = "peso"
#text widget
text = Text(grid_box, text="Cual es tu " + input_asked, grid=[0,0])
#textbox widget
textbox_peso = TextBox(grid_box, command=get_peso, grid=[1,0])
textbox_peso.bg = "white"
text_peso = Text(grid_box, text="Tu " + input_asked + " es: " + peso, grid=[0,1])
input_asked = "altura"
#text widget
text = Text(grid_box, text="Cual es tu " + input_asked, grid=[0,2])
#textbox widget
textbox_altura = TextBox(grid_box, command=get_altura, grid=[1,2])
textbox_altura.bg = "white"
text_altura = Text(grid_box, text="Tu " + input_asked + " es: " + altura, grid=[0,3])
button = PushButton(grid_box, text = "Calcular BMI", width="10", height="5", grid=[2,2], command=calcular_bmi)
text_bmi = Text(grid_box, text="Tu BMI es: " + str(bmi), grid=[1,4])
picture3 = Picture(grid_box, image="bmi.jpg", width=400, height=200, grid=[1,6])
# Display -----------------------
app.display()
(si le dais a ejecutar os dareis cuenta de cuál es el error, el texto me sale a la izquierda, las cajitas en el centro y el otro botón en la derecha y quiero que esté todo centrado)
from guizero import App, Text, Box, TextBox, PushButton, Picture
# App -----------------------
app = App(bg = "light blue",
title ="GTDM",
height = 550,
width = 650)
app.align = "center"
grid_box = Box(app, layout="grid")
# Functions and variables ---
peso = ""
def get_peso(e):
global peso
input_asked = "peso"
if (e == '\r'):
#tenemos el peso: clear text box and clear list
text_peso.clear()
text_peso.append("Tu peso es: " + peso)
textbox_peso.clear()
peso = ""
elif (e.isdigit()):
peso = peso + e
print(e)
print(peso)
else:
#no es una entrada valida
text_peso.clear()
peso = ""
app.info("error", "no es " + input_asked + " valida")
altura = ""
def get_altura(e):
global altura
input_asked = "altura"
if (e == '\r'):
#tenemos la edad: clear text box and clear list
text_altura.clear()
text_altura.append("Tu altura es: " + altura)
textbox_altura.clear()
altura = ""
elif (e.isdigit()):
altura = altura + e
print(e)
print(altura)
else:
#no es una entrada valida
text_altura.clear()
altura = ""
app.info("error", "no es " + input_asked + " valida")
bmi = 0
def calcular_bmi():
if ((altura != "") and (peso != "")):
global bmi
l = int (altura)
p = int (peso)
bmi = p / ((l/100)**2)
text_bmi.clear()
text_bmi.append("Tu BMI es: " + str('{0:.2f}'.format(bmi)))
if (bmi >= 25.0 and bmi <= 29.9):
tipo_bmi = "Sobrepeso (no obesidad)"
elif (bmi >= 30 and bmi <= 34.9):
tipo_bmi = "Obesidad clase 1 (de bajo riesgo)"
elif (bmi >= 35 and bmi <= 39.9):
tipo_bmi = "Obesidad clase 2 (riesgo moderado)"
elif (bmi >= 40):
tipo_bmi = "Obesidad clase 3 (de alto riesgo)"
else:
app.info("error", "entra peso y altura valida")
# Widgets -----------------------
input_asked = "peso"
#text widget
text = Text(grid_box, text="Cual es tu " + input_asked, grid=[0,0])
#textbox widget
textbox_peso = TextBox(grid_box, command=get_peso, grid=[1,0])
textbox_peso.bg = "white"
text_peso = Text(grid_box, text="Tu " + input_asked + " es: " + peso, grid=[0,1])
input_asked = "altura"
#text widget
text = Text(grid_box, text="Cual es tu " + input_asked, grid=[0,2])
#textbox widget
textbox_altura = TextBox(grid_box, command=get_altura, grid=[1,2])
textbox_altura.bg = "white"
text_altura = Text(grid_box, text="Tu " + input_asked + " es: " + altura, grid=[0,3])
button = PushButton(grid_box, text = "Calcular BMI", width="10", height="5", grid=[2,2], command=calcular_bmi)
text_bmi = Text(grid_box, text="Tu BMI es: " + str(bmi), grid=[1,4])
picture3 = Picture(grid_box, image="bmi.jpg", width=400, height=200, grid=[1,6])
# Display -----------------------
app.display()
Valora esta pregunta


0