Reputation: 93
I'm having trouble with tkinter check boxes updating after enabled/disable:
edit: full, running code detailing the issue. Sorry for not prepending that I had more or less psuedo code before
from tkinter import Tk, ttk, font, PhotoImage, filedialog, END, DISABLED, NORMAL
from tkinter.ttk import *
def subloop():
for x in range(3, 25, 1):
boxes[x].configure(state=NORMAL)
boxes = []
root = Tk()
root.geometry("600x500")
root.resizable(False, False)
theme = ttk.Style()
theme.theme_use("winnative")
for x in range(0, 25, 1):
boxes.append(Checkbutton(root, state=DISABLED))
boxes[x].place(x=50, y=50 + (15 * x))
root.after(0, subloop)
root.mainloop()
Upvotes: 0
Views: 276
Reputation: 2270
When I remove the theme.theme_use("winnative")
line, your code works perfectly. The code even works perfectly, just the way it should when removing that line.
One problem could be that the winnative
theme is not scalable. If we replace it with a scalable theme, like this:
from tkinter import Tk, ttk, font, PhotoImage, filedialog, END, DISABLED, NORMAL
def subloop():
for x in range(3, 25, 1):
boxes[x].configure(state=NORMAL)
boxes = []
root = Tk()
root.geometry("600x500")
root.resizable(False, False)
theme = ttk.Style()
theme.theme_use("vista")
for x in range(0, 25, 1):
boxes.append(Checkbutton(root, state=DISABLED))
boxes[x].place(x=50, y=50 + (15 * x))
root.after(0, subloop)
root.mainloop()
We replaced the winnative
theme with the vista
theme. The result is one that is desirable.
Hope this helps!
We also need to remove the from tkinter.ttk import *
. This will make the checkbuttons pure tkinter, instead of ttk.
Upvotes: 1
Reputation: 93
To anyone seeing this issue as well, removing the "from tkinter.ttk import * " made it so that the Checkbutton was from base tkinter, not tkinter.ttk
from tkinter import Tk, ttk, font, PhotoImage, filedialog, END, DISABLED, NORMAL, Checkbutton
def subloop():
for x in range(3, 25, 1):
boxes[x].configure(state=NORMAL)
boxes = []
root = Tk()
root.geometry("600x500")
root.resizable(False, False)
theme = ttk.Style()
theme.theme_use("winnative")
for x in range(0, 25, 1):
boxes.append(Checkbutton(root, state=DISABLED))
boxes[x].place(x=50, y=50 + (15 * x))
boxes[x].deselect()
root.after(0, subloop)
root.mainloop()
Upvotes: 1