python3 Tkinter flaw in the allocation of butons

Asked

Viewed 19 times

0

good afternoon, I am trying to develop a graphical interface with python and for that I am using Tkinter but this arises a problem, whenever I try to assign a function to a button of the two one or error program and does not run or simply execute the button function without me pressing it and even if I press the button the command does not execute my code is as follows:

#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os

try:
    from tkinter import *
except ModuleNotFoundError:
    os.system('pip3 install tkinter') #instala o modulo caso ele não esteja instalado por algum razão
inftext=['Verdana','12']


class primeirajanela:
    def login(self):
        print('AAAAAAAAAAAAAAAAAAAAAA')
    def __init__(self,master=None): #Master = janela
        #criação e posicionamento dos conteiners
        frame=Frame(master)
        frame.pack()
        frame2=Frame(master)
        frame2.pack()

        self.login=Button(frame,text='login',comand=self.login())
        self.login.pack()
#Criaçao e configuração básica da janela
janela = Tk()
janela.title('PAP')
janela.resizable(width=True,height=True)
janela.geometry('800x600+100+50') #alturax largura + distanciaEsquerda +Margemtopo
#Passa os dados da janela em argumento para a classe
primeirajanela(janela)
janela.mainloop()

this supposed to be a test and it just print that I know q in this case could easily use the lambdabut it will be to have more complex commands which would make it impossible to use lambda

P.S.: if I take the parentheses in this part of the code comand=self.login program simply error and does not run

if anyone can help with the beating :(

1 answer

0


The variable you are using to create a button has the same name as the function. The Button parameter is "command".

button = Button(frame,text='login',command=self.login)
button.pack()

Browser other questions tagged

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