1

i'm working on a program that should figure out the dimensions of individual pieces in kitchen cabinet modules, so you only set: height, depth, width of the material(18mm), and then you select modules from a list and after setting the dimensions of each you should be presented with a list of pieces and their dimensions. Since all of this is somewhat standardized individual pieces's dimensions are figured out by simple math, but each consists of it's own set of operations, which should be ran once and display the results in the interface(eventually i'll figure out how to write it to an excel compatible format)

as you can see here it can get to be complex, i can work it out over time no problem, but right now i'm not sure PYGUI is what i need.

import PySimpleGUI as sg


layout1 = [[sg.Text('Altura', size=(10,1)),sg.Input('',key='Alt')],   #Height 
           [sg.Text('Densidad Placa', size=(10,1)),sg.Input('',key='Placa')],# Material's density
           [sg.Text('Profundidad', size=(10,1)),sg.Input('',key='Prof')]] #Depth
layout2 = [[sg.Text('Ancho Modulo', size=(10,1)),sg.Input('',key='WM')], #Module's width
           [sg.Text('lateral', size=(10,1)),sg.Text('',key='Lat'),sg.Text('x'),sg.Text('',key='Prof2')], #side pieces
           [sg.Text('Piso', size=(10,1)),sg.Text('',key='WM2'),sg.Text('x'),sg.Text('',key='Prof2')], # bottom piece
            [sg.Button('Go')]]
#Define Layout with Tabs         
tabgrp = [[sg.TabGroup([[sg.Tab('1', layout1),
                    sg.Tab('2', layout2)]])]]  
        
window =sg.Window("Tabs",tabgrp)
#Read  values entered by user
while True:
    event,values=window.read()
    if event in (sg.WINDOW_CLOSED, 'Close'):
       break
    elif event == 'Go':
        anc = values['WM']
        altura = values['Alt']
        placa = values['Placa']
        prof = values['Prof']
        try:
            v = int(anc) #width
            w = int(prof)#depth
            x = int(altura)#height
            y = int (placa)# Material's density
            altlat = str(x - y) #height of side pieces
            prof2 = int(w - y) #depth of pieces,(total depth incluiding the door)
            ancm = int(v) #width
        except ValueError:
            altlat = "error"
            prof2 = "error"
            ancm = "error"
        window['Lat'].update(value=altlat)
        window['Prof2'].update(value=prof2)
        window['WM2'].update(value=ancm)
        window.refresh
#access all the values and if selected add them to a string
window.close()  

i figured i use functions for every set of operations and call them as i need them, but keys can't be reused and every tutorial i've seen points towards them, and other implementations i tried failed,. i've been using python since last night, so i'm not sure how many options i have, nor how limited my options will be with PYGUI's toolset.

Ax31
  • 11
  • 1

1 Answers1

0

I think what you are asking is, how can I make a function that will take the values and run an operation on them? This seems to be more of a general python question than one about pyGUI, but here is a quick answer.

def calc_side_panel_height(altura, placa):
  x = int(altura)#height
  y = int (placa)# Material's density
  return (x - y) #height of side pieces


try {
   height_of_side = calc_side_panel_height(altura, place)
   # use height here. 
   altlat = str(height_of_side)
}

does that start to make sense? You would call functions and in those functions do the calculations, so you don't have to rewrite the code.

more info: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Functions

Let me know if I'm confused!

nycynik
  • 7,371
  • 8
  • 62
  • 87
  • actually, my question was more about planning ahead, but during writing i realized the problem were the keys, since they can't be reused, i have to go with variables instead. now, you declare them, define a function, and call it, right? but with PYGUI i have to declare the layout _before_ calling the function, so `sg.text(' ')` can become `sg.text(var)` – Ax31 Aug 13 '22 at 06:47
  • but it's display value doesnt uptate according to the functions. even after a window refresh. Basically i cant figure out how to implement the ui. – Ax31 Aug 13 '22 at 07:15
  • yes, that is right, you can update the text with a function, as long as you have a reference to the window. I think this will help you https://stackoverflow.com/questions/57072250/updating-gui-items-withing-the-process – nycynik Aug 17 '22 at 19:42