Can't Get Entry Var in Tkinter - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Can't Get Entry Var in Tkinter (/thread-24537.html) |
Can't Get Entry Var in Tkinter - OCaraDoBaixo - Feb-18-2020 class Classe1(): def button_label(self, chosen_row, textoescrito, variavel): lb1 = Label(frame2, text=textoescrito, bg=color2, font=('Roboto', 11)) lb1.grid(row=chosen_row, column=2, padx=2, pady=2) self = Entry(frame2, width=50, font=('Roboto', 11), textvariable=variavel) self.grid(row=chosen_row + 1, column=2, padx=2, pady=2) def button_label2(self, chosen_row, textoescrito, variavel): lb1 = Label(frame2, text=textoescrito, bg=color2, font=('Roboto', 11)) lb1.grid(row=chosen_row, column=3, padx=2, pady=2) self = Entry(frame2, width=50, font=('Roboto', 11), textvariable=variavel) self.grid(row=chosen_row + 1, column=3, padx=2, pady=2) def get1(self): self = StringVar.get() text1 = Classe1() text1.button_label(3, 'Razão Social:', 'razao') text2 = Classe1() text2.button_label(5, 'Nome Fantasia:', 'nomefantasia') text3 = Classe1() text3.button_label(7, 'Endereço:', 'endereco') text4 = Classe1() text4.button_label(9, 'Responsável Legal:', 'res_legal') text5 = Classe1() text5.button_label(11, 'Telefone:', 'telefone') text6 = Classe1() text6.button_label(13, 'CNPJ:', 'cnpj') text7 = Classe1() text7.button_label2(3, 'Data:', 'data') text8 = Classe1() text8.button_label2(5, 'Email:', 'email') text9 = Classe1() text9.button_label2(7, 'Horário de funcionamento:', 'horario') text10 = Classe1() text10.button_label2(9, 'Área total(m3):', 'areatotal') text11 = Classe1() text11.button_label2(11, 'Cpf do responsável legal', 'cpf1') text12 = Classe1() text12.button_label2(13, 'Responsável pela implantação:', 'res_imp1') app.mainloop()When I try to use 'razao' etc, it gives me this code:
RE: Can't Get Entry Var in Tkinter - Larz60+ - Feb-18-2020 textvariable must be a tkinter.StringVar, not a raw string. you can remedy this by declaring a string var in button_label, seting it from the argument variavel and using the new StringVar as the textvariable (cod not tested): class Classe1(): def __init__(self): self.svar = StringVar() def button_label(self, chosen_row, textoescrito, variavel): self.svar.set(variavel) lb1 = Label(frame2, text=textoescrito, bg=color2, font=('Roboto', 11)) lb1.grid(row=chosen_row, column=2, padx=2, pady=2) self = Entry(frame2, width=50, font=('Roboto', 11), textvariable=self.svar) self.grid(row=chosen_row + 1, column=2, padx=2, pady=2) |