Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Can't Get Entry Var in Tkinter
#1
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:
Error:
Exception in Tkinter callback Traceback (most recent call last): File "c:\users\joaog\appdata\local\programs\python\python38-32\Lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "GUI.py", line 21, in clicked doc.add_paragraph(res_legal, style='Heading 1') NameError: name 'res_legal' is not defined
Quote
#2
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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Getting Input from Tkinter Entry juliabrushett 6 11,253 May-30-2020, 03:29 PM
Last Post: Larz60+
  Converting Entry field value to integer in tkinter scratchmyhead 2 110 May-11-2020, 03:41 PM
Last Post: scratchmyhead
  [Tkinter] Tkinter adding entry values scratchmyhead 1 148 May-04-2020, 05:21 AM
Last Post: Yoriz
  [Tkinter] Entry box not showing 2 decimal places Chuck_Norwich 3 151 Apr-24-2020, 05:28 PM
Last Post: deanhystad
  Always lowercase entry in tkinter ReturnName 8 301 Apr-18-2020, 09:41 AM
Last Post: PeroPuri
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 1,032 Jan-23-2020, 09:00 PM
Last Post: HBH
  Newbie question with Tkinter Entry mariolopes 2 346 Oct-12-2019, 11:02 PM
Last Post: Larz60+
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 992 Mar-18-2019, 05:36 PM
Last Post: woooee
  [Tkinter] Tkinter Entry widget and KeyPad intrgration chiragarya1992 0 2,206 Aug-11-2018, 01:09 AM
Last Post: chiragarya1992
  [Tkinter] How to show and hide tkinter entry box when select yes from drop down Prince_Bhatia 1 2,504 Jun-12-2018, 08:05 AM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)