lundi 20 mai 2019

Tkinter Checkbutton variable doesnt change on second window level

I have a button on a Tkinter window, which leads me to a second Tkinter window with some Checkbuttons. If i click them their assigned variable doesnt change. The second window just by itself works fine.

test2.py

from Tkinter import *
import test

window = Tk()
btn = Button(window, command=test.main)
btn.pack()
window.mainloop()

test.py

from Tkinter import *
from functools import partial

def func(n):
  print var[n].get()


def main():
  window = Tk()
  global var 
  var = [IntVar(), IntVar()]

  i = 0
  ck = Checkbutton(window, variable=var[i], command=partial(func,i))
  ck.grid(row = 0, column = 0)

  i += 1
  ck2 = Checkbutton(window, variable=var[i], command=partial(func,i))
  ck2.grid(row = 1, column = 0)

  window.mainloop()

# main()




Aucun commentaire:

Enregistrer un commentaire