0
I’m having the following problem: I can get the value of a dynamic variable (checkbutton) when the whole program is in one file with only one function:
import string
from tkinter import *
import tkinter as tk
qtdvinhos = 3
linhacheck = 1
var=dict()
mostra = Tk()
mostra.geometry("650x400")
mostra.title("Sydvinn - Vinhos cadastrados")
def Lecheck(event):
for x in range(1,qtdvinhos):
stringcheck = 'Check ' + str(x) + ': ' +str(var[x].get())
print(stringcheck)
for x in range(1,qtdvinhos):
var[x]=IntVar()
check1 = Checkbutton(mostra, variable=var[x])
check1.grid(row=linhacheck, column=0)
linhacheck= linhacheck+1
button_excluir = Button(mostra, text="Pega Valor")
button_excluir.bind("<Button-1>", Lecheck)
button_excluir.grid(row=4, column=4)
mostra.mainloop()
However if I separate the code into two files, each one on a screen and two modules, I can only get the values 0 of the checkboxes:
File 1: Duasjanelaspt2
import string
from tkinter import *
import tkinter as tk
class ChamaClasse:
global Lecheck
global var
var={}
global qtdvinhos
qtdvinhos = 3
def Lecheck(event):
for x in range(1,qtdvinhos):
stringcheck = 'Check ' + str(x) + ': ' +str(var[x].get())
print(stringcheck)
def Abrejanela(event):
global linhacheck
linhacheck = 1
mostra = Tk()
mostra.geometry("650x400")
mostra.title("Sydvinn - Vinhos cadastrados")
for x in range(1,qtdvinhos):
var[x]=IntVar()
check1 = Checkbutton(mostra, variable=var[x])
check1.grid(row=linhacheck, column=0)
linhacheck= linhacheck+1
button_excluir = Button(mostra, text="Pega Valor")
button_excluir.bind("<Button-1>", Lecheck)
button_excluir.grid(row=4, column=4)
mostra.mainloop()
Archive 2: Duasjanelaspt2
import string
from tkinter import *
import tkinter as tk
from DuasJanelasPT1 import ChamaClasse
novo = Tk()
novo.geometry("650x400")
novo.title("Sydvinn - Vinhos cadastrados")
checks = dict()
button_excluir = Button(novo, text="Chama o Mechama")
checks = button_excluir.bind("<Button-1>", ChamaClasse.Abrejanela)
button_excluir.grid(row=4, column=4)
novo.mainloop()
Can someone help me with this?