I have a problem with TKinter radiobuttons, checkerboxes, buttons and fields. I'm not sure if I can put multiple questions in one but basically it's a single question but quite big. First part is that I can't setup my checkerboxes correctly. I wrote a gray bg and almost white fg but on Mac it shows everything in white. I'll attach a few screenshots but I think I described my problem really well. Here is a part of the code with a problem:
buttonVR = tk.Button(window, bg="gray15", text=f"{modes[0]}", font=("Arial", 10), activebackground="black", fg="lemon chiffon", command=VR, width=24, height=3)
import tkinter.messagebox as tmb
import tkinter.filedialog as tfd
from tkinter.ttk import Radiobutton
from tkinter import *
from tkinter.ttk import Checkbutton
import tkinter as tk
import re
import math
global window
def MainWindow():
def HelpMain():
tmb.showinfo(f"Help", "blah-blah-blah, demo v")
window = tk.Tk()
window.title(f"{app_name} {version} by {company}")
window.geometry("500x240")
window.configure(bg="gray22", border= "10")
window.resizable(False, False)
buttonVR = tk.Button(window, bg="gray15", text=f"{modes[0]}", font=(
"Arial", 10,), activebackground="black", fg="lemon chiffon", command=VR, width=24, height=3)
buttonVR.grid(column=0, row=0, pady=5)
buttonPR = tk.Button(window, bg="gray15", text=f"{modes[1]}", font=(
"Arial", 10), activebackground="black", fg="lemon chiffon", command=PR, width=24, height=3)
buttonPR.grid(column=0, row=1, pady=10)
buttonAR = tk.Button(window, bg="gray15", text=f"{modes[2]}", font=(
"Arial", 10), activebackground="black", fg="lemon chiffon", command=AR, width=24, height=3)
buttonAR.grid(column=0, row=2, pady=5)
buttonHelp = tk.Button(window, bg="gray15", text="Help", font=(
"Arial", 10), activebackground="black", fg="lemon chiffon", command=HelpMain, width=4, height=1)
buttonHelp.place(anchor='se', x=480, y=220)
window.mainloop()
Second problem is that I can't take information from a checkerbox. I need to take true/false to activate/deactivate a text field here is a part with a checkerbox itself:
height_chk_state = BooleanVar()
height_chk_state.set(False)
height_chk = tk.Checkbutton(windowVR, border= "5", bg="gray22", selectcolor="gray15", fg="lemon chiffon", text='Height', var=height_chk_state)
height_chk.grid(column=0, row=3)
And here is the full code of a window with checkerboxes:
import tkinter as tk
from tkinter import Radiobutton
from tkinter import *
import tkinter.messagebox as tmb
import tkinter.filedialog as tfd
from tkinter.ttk import Checkbutton
global windowVR
def HelpVR():
tmb.showinfo(f"Help",
"blah-blah-blah")
windowVR = tk.Tk()
windowVR.resizable(False, False)
windowVR.geometry("400x150")
windowVR.title(f"test")
windowVR.configure(bg="gray22", borderwidth=10)
width_chk_state = BooleanVar()
width_chk_state.set(False)
width_chk = tk.Checkbutton(windowVR, border= "5", bg="gray22", fg="lemon chiffon", selectcolor="gray15", text='Width ', var=width_chk_state)
width_chk.grid(column=0, row=1)
height_chk_state = BooleanVar()
height_chk_state.set(False)
height_chk = tk.Checkbutton(windowVR, border= "5", bg="gray22", selectcolor="gray15", fg="lemon chiffon", text='Height', var=height_chk_state)
height_chk.grid(column=0, row=3)
ratio_chk_state = BooleanVar()
ratio_chk_state.set(False)
ratio_chk = tk.Checkbutton(windowVR, border= "5", bg="gray22", fg="lemon chiffon", selectcolor="gray15", text='Ratio ', var=ratio_chk_state)
ratio_chk.grid(column=0, row=5)
global width_condition
global height_condition
global ratio_condition
width_condition = "readonly"
height_condition="readonly"
ratio_condition="readonly"
while 1>0:
if width_chk_state is True:
width_condition="normal"
print(width_condition)
else:
width_condition = "readonly"
print(width_condition)
if height_chk_state is True:
height_condition="normal"
print(height_condition)
else:
height_condition="readonly"
print(height_condition)
if ratio_chk_state is True:
ratio_condition="normal"
print(height_condition)
else:
ratio_condition="readonly"
print(ratio_condition)
Width = tk.Entry(windowVR, width=30, font=(
"Arial", 10), bg="gray12", fg="lemon chiffon", state=f"{width_condition}")
Width.grid(column=5, row=1)
Height = tk.Entry(windowVR, width=30, font=(
"Arial", 10), bg="gray12", fg="lemon chiffon", state=f"{height_condition}")
Height.grid(column=5, row=3)
Ratio = tk.Entry(windowVR, width=30, font=(
"Arial", 10), bg="gray12", fg="lemon chiffon", state=f"{ratio_condition}")
Ratio.grid(column=5, row=5)
print(width_condition)
print(height_condition)
print(ratio_condition)
windowVR.mainloop()
I know that windows looks ugly at the moment but it's just a beginning of a demo so please be condescending to my code:) In terms of colors I tried almost every fitting parameter in buttons and stuff. I solved a problem with checkerboxes by changing the 'selectcolor' to black but it is not working with other types of objects. I tried to create a while cycle to check checkerboxes' conditions but either it falls to an infinite loop without any possibility to go further through code or I just can't refresh it without any stops.