Send or Update button in Tkinter (Python) and Widgets Resizing

Asked

Viewed 1,022 times

1

Start a code where you have 4 Checksbuttons and I want to do the following: (pseudo-code) user enters the database name, and selects what he wants => name, email, Cpf, color after that the program picks and checks which is selected, after checking if name was marked grab and create a name data in the table and so on. my difficulty and in checking whether or not Checkbutton is marked and if you take and do something.

Another problem is in resizing widgets type that put the entry in such place but it is only 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()

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 shape, which is even quite similar to the one I had 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 appears the message Marcado, and when it clears Desmarcado. Now all you have to do is fit your code.

Entry:

To the Entry() To be left is just to put what you put in others, side=LEFT, hope I’ve helped.

Browser other questions tagged

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