Send or update button in Tkinter (Python) and Widget Resizing

1

Start a code in which you have 4 ChecksButtons and I wanted to do the following: (pseudo-code) user types the name of the database, and selects what he wants = > name, email, cpf, color after that the program picks up and verifies which is selected, after checking if name was marked handle and create a data of the name in the table and so on. my difficulty and in checking if the CheckButton is or is not marked and if it has taken and does something.

Another problem of mine is in resizing widgets of type that put the entry in such a place but it only stays at the top.

from tkinter import *

class criar(object):
    def __init__(self, principal):
#frames e empacotamento de frames
        self.font = ('Arial', '18', 'bold')
        self.frame1 = Frame(principal)
        self.frame1.place()
        self.frame1.pack()
        self.frame2 = Frame(principal)
        self.frame2.place()
        self.frame2.pack()
        self.subFrameOptions = Frame(self.frame2)
        self.subFrameOptions.place()
        self.subFrameOptions.pack()
#texto exibido na tela
        for i in range(15):
           L3 = Label(self.frame1, text = '\t\t\t\t\t\t', bg = '#B5B5B5')
           L3.pack()
        L1 = Label(self.frame1, font = self.font, text = "  Nome do Seu Banco de Dado  ", bg = '#696969')
        L1.place(x = 10,y = 10)
        L1.pack()
        E1 = Entry(self.frame1, bd = 5, highlightcolor = '#1E90FF')
        E1.place(x = 40,y = 10)
        E1.pack()
        L2 = Label(self.frame1, text = '\t\t\t\t\t\t', bg = '#B5B5B5')
        L2.pack()
#checkButtons
        self.nome = Checkbutton(self.subFrameOptions, bd = 5, text = 'Nome', variable = Vnome)
        self.nome.pack(side = LEFT)
        Vnome.get()
        self.cor = Checkbutton(self.subFrameOptions, bd = 5, text = 'Cor', variable = Vcor)
        self.cor.pack(side = LEFT)
        Vcor.get()
        self.cpf = Checkbutton(self.subFrameOptions, bd = 5, text = 'CPF', variable = Vcpf)
        self.cpf.pack(side = LEFT)
        Vcpf.get()
        self.email = Checkbutton(self.subFrameOptions, bd = 5, text = 'Email', variable = Vemail)
        self.email.pack(side = LEFT)
        Vemail.get()


principal = Tk()
#variaveis dos metodos dos checkButtons
Vnome = IntVar()
Vcor = IntVar()
Vcpf = IntVar()
Vemail = IntVar()
#cria a instancia
criar(principal)
principal['bg'] = '#B5B5B5'
principal.geometry('400x300')
principal.title("Gerenciador de Cadastro")
principal.mainloop()
    
asked by anonymous 16.05.2017 / 02:38

1 answer

2

I had posted a solution that I had found to know when the box was checked, but now I edited it because I found the correct form, which is very similar to the one I put here.

The explanation of how to recognize is within the algorithm.

from tkinter import *

class exemplo:
    def __init__(self, tk):
        self.frame1 = Frame(tk)
        self.frame2 = Frame(tk)

        self.frame1.pack()
        self.frame2.pack()

        self.aviso = Label(self.frame2, text='Desmarcado')
        self.aviso.pack()

        self.es_C1 = IntVar() #self.es_NomeVariável = IntVar(), explico o que é IntVar() lá embaixo.
        self.C1 = Checkbutton(tk, text = "Music",  height=2,
                 width = 15, command=self.marcada, variable=self.es_C1, onvalue=1, offvalue=0)
"""
* "onvalue" é o valor que será dado quando a caixa estiver marcada, aqui eu defini 1, mas não é necessário coloca-la dentro do CheckButton, o valor é sempre 1
* "offvalue" é o inverso, eu defini 0, também não precisa colocar, valor padrão é sempre 0.
* Só coloca "onvalue" e "offvalue" se você você quiser colocar um valor diferente como "marcado" ou "desmarcado", eles sempre estarão presentes na função com valor 1 e 0 respectivamente.
* "variable" é onde é "depositado" o estado atual do CheckButton, definido por "onvalue" e "offvalue".
"""
        self.C1.pack()
    def marcada(self):
        if self.es_C1.get() == 1: #utilizamos .get() para pegarmos o valor da variável e comparamos com 1, se estiver marcado, exibe o aviso de marcado.
            self.aviso['text'] = 'Marcado'
        else:
            self.aviso['text'] = 'Desmarcado'
ex = Tk()
exemplo(ex)
ex.mainloop()

Checking the message above the box, you see that when you mark it, you see the message Marcado , and when you clear Desmarcado . Now you can only fit your code.

Entry:

For the Entry() left, just put what you put in the others, side=LEFT , I hope I have helped.

    
16.05.2017 / 03:51