Jul-06-2020, 11:21 PM
(This post was last modified: Jul-06-2020, 11:21 PM by kenwatts275.)
Hello all,
I am writing a program that utilizes a large array of checkbuttons.
When run, the user clicks on the checkbuttons that they want to select, then upon clicking the Go button, it saves the states of the buttons into a text file. Subsequent runs of the program read the text file and set the checkbuttons as checked or unchecked based on the values in text file. However, when I run my program, all the checkbuttons appear with a black box in them regarless of the values in the text file.
Below is a pared down version of the code.
If anyone can explain how to fix this, it would be greatly appreciated.
Thanks in advance.
Edit: I tried running the exact same program on my Fedora LINUX server and it works fine. The error appears when the program is run on Windows or Cygwin. Any help to fix this program in Windows or Cygwin would be appreciated.
Thanks in advance.
I am writing a program that utilizes a large array of checkbuttons.
When run, the user clicks on the checkbuttons that they want to select, then upon clicking the Go button, it saves the states of the buttons into a text file. Subsequent runs of the program read the text file and set the checkbuttons as checked or unchecked based on the values in text file. However, when I run my program, all the checkbuttons appear with a black box in them regarless of the values in the text file.
Below is a pared down version of the code.
If anyone can explain how to fix this, it would be greatly appreciated.
Thanks in advance.
Edit: I tried running the exact same program on my Fedora LINUX server and it works fine. The error appears when the program is run on Windows or Cygwin. Any help to fix this program in Windows or Cygwin would be appreciated.
Thanks in advance.
from tkinter import * from tkinter import ttk import os from os.path import expanduser from pathlib import Path def save_defaults(args): default_values = open(default_file,"w+") for x in args: default_values.write(x+"\n") default_values.close() def main_program(): button_values = [] for i in range(6): if check_buttons[i].instate(['selected']): button_values.append("1") else: button_values.append("0") save_defaults(button_values) print("Finished\n") mw = Tk() # 999x999 is size of window, 999+999 is the location of the window mw.geometry('700x300+400+200') mw.title(__file__) current_file = Path(__file__).stem default_file = expanduser("~")+"/python/"+current_file+".default" # If file does not exist, create one if not os.path.isfile(default_file): cmd = "type NUL > " + default_file # cmd = "touch " + default_file # for LINUX operating system os.system(cmd) default_values = open(default_file,"r") frame3 = Frame(mw) framebot = Frame(mw) frame3.pack(side=TOP,fill=X) framebot.pack(side=BOTTOM,fill=X) w3 = Label(frame3, text="Checkbuttons: ",font=("Times",16)).grid(row=0,column=0) check_buttons = [] row_val = 0 col_val = 1 for i in range(6): temp_value = default_values.readline() check_buttons.append(ttk.Checkbutton(frame3,text=str(i+1))) check_buttons[i].state(["selected"]) if (temp_value.strip() == "") or (temp_value.strip() == "0"): check_buttons[i].state(["!selected"]) check_buttons[i].grid(row=row_val,column=col_val) col_val += 1 if col_val > 3: col_val = 1 row_val += 1 btn3 = Button(framebot,text='Go',font=("Times",16),command=main_program).pack(side="left") btn4 = Button(framebot,text='Exit',font=("Times",16),command=mw.quit).pack(side="right") default_values.close() mw.mainloop()