2

I am trying to make a GUI element invisible by using visible=False. It appears that the update function works with every other attribute as well as for values s shown in the code below, except for the visible attribute. Specifically, although the program requests that element (2,2) become invisible, element (4,2) is becoming invisible. Any help with this will be greatly appreciated. Thanks

import PySimpleGUI as sg

layout = [[sg.B(' ', size=(8,4), key=(i,j)) for i in range(0,5)] for j in range(0,4)]

window = sg.Window('Trying to change attribute', layout).Finalize()
window.Maximize()

while True:             # Event Loop
    event, values = window.read()
    print(event, values)
    window[(1,1)].update(button_color=('blue','yellow'))
    window[(2,2)].update(visible=False)  ## Problem here
    window[(3,3)].update('Hello')

    if event in (None, 'Exit'):
        break
    current_marker = window[event].get_text()

Raj
  • 43
  • 1
  • 6
  • I have also reproduced it and confirmed it. The same event occurred when I used a string instead of a numerical tuple format. You should definitely post the issue on the developer's [Github](https://github.com/PySimpleGUI/PySimpleGUI/issues) and submit your issue. – r-beginners Jun 07 '20 at 03:02
  • Actually, only element (2,2) invisible, not element (4, 2). Here, elements or widgets after the invisible element will be moved farward. Not issue on PySimpleGUI, also not on tkinter. – Jason Yang Mar 22 '21 at 06:00

2 Answers2

1

The behaviour that you are experiencing is due to the fact that the elements that are made invisible loose their position in the layout. In other words, element (2,2) disappears. If you'd make it visible later, it will appear at the end of its respective row.

In most cases, this is not the behaviour we'd want. You can prevent it by reserving a place for the element using a function like place() shown below:

import PySimpleGUI as sg


def place(elem, size=(None, None)):
    return sg.Column([[elem]], size=size, pad=(0, 0), element_justification='center')


def test():
    layout = [[place(sg.B(' ', size=(8, 4), key=(i, j))) for i in range(0, 5)] for j in range(0, 4)]

    window = sg.Window('Trying to change attribute', layout).Finalize()
    window.Maximize()

    while True:  # Event Loop
        event, values = window.read()
        if event in (None, 'Exit'):
            break
        print(event, values)
        window[(1, 1)].update(button_color=('blue', 'yellow'))
        window[(2, 2)].update(visible=False)
        window[(3, 3)].update('Hello')

This is the result:

enter image description here

0

The code working properly.

befor click

when you click any button. it update visible=False and it remove from the screen. so button (3,2) and (4,2) shift left side. so , we think that (4,2) is invisible instead of (2,2).

enter image description here

you may also check with disabling button.

window[(2,2)].update(disabled=True)

enter image description here

Bhargav Desai
  • 941
  • 1
  • 5
  • 17