I'm having the following problem:
I can get the value of a dynamic variable (checkbutton) when the whole program is in a single 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 0 values of the checkboxes:
File 1: TwoWindows2
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()
File 2: TwoWindows2
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 anyone help me with this?