FreeSimpleGUI icon indicating copy to clipboard operation
FreeSimpleGUI copied to clipboard

error : bad option "variable"

Open ca4ti opened this issue 10 months ago • 5 comments

I have problem , with last version , not work same codice work like on pysimplegui .

import FreeSimpleGUI as sg

# Definindo a layout da calculadora
layout = [
    [sg.Text('Calculadora')],
    [sg.InputText(key='-DISPLAY-')],
    [sg.Button('7'), sg.Button('8'), sg.Button('9'), sg.Button('+')],
    [sg.Button('4'), sg.Button('5'), sg.Button('6'), sg.Button('-')],
    [sg.Button('1'), sg.Button('2'), sg.Button('3'), sg.Button('*')],
    [sg.Button('0'), sg.Button('.'), sg.Button('='), sg.Button('/')],
    [sg.Button('C')]
]

# Criando a janela da calculadora
window = sg.Window('Calculadora', layout)

while True:
    # Lendo eventos
    event, values = window.read()
    
    if event == 'C':  # Botão "C" para limpar a tela
        window['-DISPLAY-'].update('')
        
    elif event == '=':  # Botão "=" para calcular
        try:
            resultado = eval(values['-DISPLAY-'])
            window['-DISPLAY-'].update(str(resultado))
        except Exception as e:
            window['-DISPLAY-'].update('Error')
            
    else:  # Atualizando a tela com o valor do botão pressionado
        window['-DISPLAY-'].update(values['-DISPLAY-'] + event)
        
# Fecha a janela da calculadora quando fechada pelo usuário
window.close()
>>>python3 --version 
Python 3.13.1
>>>brew list python-tk
/opt/homebrew/Cellar/[email protected]/3.13.1/libexec/_tkinter.cpython-313-darwin.so
/opt/homebrew/Cellar/[email protected]/3.13.1/sbom.spdx.json

>>>sw_vers
ProductName:            macOS
ProductVersion:         14.5
BuildVersion:           23F79
>>>pip list
Package              Version
-------------------- ---------
engineering-notation 0.10.0
FreeSimpleGUI        5.1.1
FreeSimpleGUIWeb     1.0.0
pip                  25.0
pyasn1               0.6.1
PySimpleGUI          5.0.8
remi                 2020.3.10
rsa                  4.9
stringify            0.1.1
tk                   0.1.0
tk-tools             0.17.0
wheel                0.45.1

Error :

Exception has occurred: TclError
bad option "variable": must be add, info, or remove
  File "/Users/XXX/Downloads/import FreeSimpleGUI as sg.py", line 19, in <module>
    event, values = window.read()
                    ~~~~~~~~~~~^^
_tkinter.TclError: bad option "variable": must be add, info, or remove

ca4ti avatar Feb 04 '25 08:02 ca4ti

Hmm. I'm not able to reproduce this issue on my Windows machine. Your code works for me as-is.

spyoungtech avatar Feb 04 '25 10:02 spyoungtech

I will be able to try reproducing on a MacOS system in the near future. Hang tight. (and thank you for the detailed report!).

For whatever it's worth, I've found that using the official Python installer (which bundles its own TCL/TK) is the most reliable. In the meantime, if you would consider giving that a try and letting me know if it fixes it, I would appreciate it.

spyoungtech avatar Feb 04 '25 18:02 spyoungtech

Same here. Homebrew's python-tk was packaged with Tcl-Tk@9 that caused the issue. I installed and used official python (with tcl-tk@8) and the issue disappeared.

hanhha avatar Feb 17 '25 16:02 hanhha

Related: #45

spyoungtech avatar Mar 06 '25 10:03 spyoungtech