PYTHON LAYOUT ATTRIBUTE ERROR

Asked

Viewed 75 times

0

I’m doing a project in Python with Pysimplegui using Sg for simple layout, but the Pycharm terminal returns me the error of missing value assignment tried to go through the powershell terminal and cmd and gave the same error

import PySimpleGUI as sg

class TelaPython:
    def _init_(self):

        layout = [
            [sg.Text('Nome'),sg.Input()],
            [sg.Text('Senha'),sg.Input()],
            [sg.Button('Login')],
            [sg.Button('Cadastrar')],

        ]

        janela = sg.Window(Login).layout(layout)

        self.button, self.values = janela.Read()

    def Iniciar(self):
        print(self.values)

tela = TelaPython()
tela.Iniciar()

1 answer

2

You are trying to access a class variable that was not created.

  self.values = janela.Read()

Add the variable and try again.

import PySimpleGUI as sg

class TelaPython:
    
    values = ''

    def _init_(self):

        layout = [
            [sg.Text('Nome'),sg.Input()],
            [sg.Text('Senha'),sg.Input()],
            [sg.Button('Login')],
            [sg.Button('Cadastrar')],
        ]

        janela = sg.Window(Login).layout(layout)

        self.button, self.values = janela.Read()

    def Iniciar(self):
        print(self.values)

tela = TelaPython()
tela.Iniciar()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.