# Any one help me code finish this by PySimpleGUI

## Issue

I have to make a program to teach children multipliers, this is the core code of the assignment.

``````#include <stdio.h>

#define MIN       1
#define MAXINDEX  10
#define MAXTABLE  10
#define STEP      1

void main(void)
{
int i,j ;

for (j = MIN; j <MAXTABLE; j += STEP)  {
for (i = MIN; i <= MAXINDEX; i += STEP)
printf(“%3d * %3d = %3d\n”, i, j, i*j);
printf(“\n---------------\n\n”);
}

for (i = MIN; i <= MAXINDEX; i += STEP)
printf(“%3d * %3d = %3d\n”, i, MAXTABLE, i*MAXTABLE);
}
``````

After I have to rewrite it to a next generation language so I designed to write it in python.
Like this

``````j=1
i=1
for j in range(1,11):
for i in range(1,11):
print('%3d * %3d =%3d' % (i, j, i *j))
if j!=10:
print("\n---------------\n")
else:
print("\n")
``````

And after that I have to make a UI for it so this image is what I designed to do like this This is the design of me

Since I just study python for 3 days, so I try my best to write this:

``````import PySimpleGUI as sg
import os.path
def Corecode():
j=1
i=1
for j in range(1,11):
for i in range(1,11):
print('%3d * %3d =%3d' % (i, j, i *j))
if j!=10:
print("\n---------------\n")
else:
print("\n")
from PySimpleGUI.PySimpleGUI import R, Image, Multiline
showrobot_column = [
[sg.Image('E:\img\robot.png',size = (300,300))],
],
show_Textbox_selectbox = [
[sg.Multiline(size=(50,20),key='-def-')],
[sg.Listbox(values=['a','b','c','d'], enable_events=True, size=(50,20), key="")]

]

layout = [
[sg.Column(showrobot_column),
sg.VSeparator(),
sg.Column(show_Textbox_selectbox)
]
]
window = sg.Window("First Test",layout)
while True:
if event == sg.WIN_CLOSED:
break
window.close()
``````

I designed to make it like a robot is talking and let the children interact by buttonBut, but I find out I can’t insert the image, and also I can’t find a way to print the Multiplier table by the core code that on the front, so someone can help me to finish the code or tell me why the sg.image get error. TY

## Solution

Try this,

``````import PySimpleGUI as sg

def corecode(base):
return ("\n"+"-"*13+"\n").join([f'{i+1:>2d} * {base:>2d} = {(i+1)*base:>3d}' for i in range(10)])

sg.theme('DarkBlue3')
sg.set_options(font=("Courier New", 12))

showrobot_column = [
[sg.Image('E:/img/robot.png', size = (300, 300))],
]

list_values = [f'{i+1:>2d}' for i in range(10)]
show_Textbox_selectbox = [
[sg.Multiline(size=(15, 20), expand_y=True, key='-MULTILINE-')],
[sg.Listbox(values=list_values, enable_events=True, size=(15, 10), key="-LISTBOX-")],
]

layout = [
[sg.Column(showrobot_column),
sg.VSeparator(),
sg.Column(show_Textbox_selectbox),],
]

window = sg.Window("First Test", layout, finalize=True)
multiline = window['-MULTILINE-']
multiline.update(value=corecode(1))
listbox = window['-LISTBOX-']
listbox.update(set_to_index=0)
while True:
if event == sg.WIN_CLOSED:
break
elif event == '-LISTBOX-':
base = int(values[event])
multiline.update(value=corecode(base))

window.close()
`````` 