Jan-07-2023, 12:47 PM
(This post was last modified: Jan-07-2023, 01:54 PM by Yoriz.
Edit Reason: Removed double quote of previous post and added the posters name instead
)
I used @Yoriz approach, since it was closer to my original attempt; though this is also similar to the first suggestion, which I also tried.
When I attempted the first one, I encountered a problem that I thought this one would resolve, but it didn't.
The issue comes about in that I have 36 different graph types I need to consider. Having these in a single column is, therefore, not an option.
I introduced two variables,
This worked nicely, with the code now looking like this...
This does not happen if I simply use the
The references to each button in the list
Any ideas?
Total code is here...
When I attempted the first one, I encountered a problem that I thought this one would resolve, but it didn't.
The issue comes about in that I have 36 different graph types I need to consider. Having these in a single column is, therefore, not an option.
I introduced two variables,
row
and col
, incrementing these accordingly (row
by 1 each time, reset to 0 when row == 10
and incremented col
by 1.This worked nicely, with the code now looking like this...
self.radio_buttons = [] col = 0 row = 0 for graph_type in graph_types: text, value = graph_type radio_button = customtkinter.CTkRadioButton(self, text=text, value=value, variable=self.radio_button_var) radio_button.grid(row=row, column=col, padx=5, pady=5, sticky="W") self.radio_buttons.append(radio_button) row += 1 if (row == 20): col += 1 row = 0Here's the issue, if I select one radio button then, on occasion, others are also selected?!?
This does not happen if I simply use the
index
as the row
reference (though this runs off the page).The references to each button in the list
self.radio_buttons
are unique and this is not changing. The relationship between the active buttons is not apparent ([5, 25, 27], [22, 36]) and, as you can see from that list, this only occurs for 5 buttons?!?Any ideas?
Total code is here...
import customtkinter graph_types = [["Tbol-age - tauir-age", "TLTAge"], ["Makes the coffee", "MtC"], ["Lbol - Lshock (Class 1 data)", "LL1"], ["Lbol - CO Momentum","LCM"], ["Tbol - Lbol","TL"], ["Menv - H2","MH2"], ["Lbol - Lshock (Class 0 data)","LL0"], ["Tbol - H2","TH2"], ["Mcor - Lbol + Molinari data + Elia data","MLME"] , ["Probability Diagram","Prob"], ["Mstar - Tstar","MS_TS"], ["Mstar - Rstar","MS_RS"], ["Fco * x / Lbol vs Menv / Lbol^0.6","FLML"], ["Lbol - Tbol (combined)","LTC"], ["Mstar - Lbol","MS_L"], ["Mcor - Lbol + (M + E) - different axes","ML"], ["Mcor - Lbol ???","ML_Unknown"], ["TEST Time - Rstar","TEST1"], ["TEST Time - Lint","TEST2"], ["Menv - Lbol - L(Ly) / Lbol","MLLL"], ["Mstar - Lbol / Ledd","MLL"], ["Tstar - Lbol","TS_L"], ["Time - Tbol","TT"], ["Tbol - Mclump / Lbol","TML"], ["Tstar - Lint","TL"], ["Single histogram for L/M","SLM"], ["Time - Lbol","TL"], ["Tbol isotherms","TI"], ["HR Diagram for Lint and Lbol tracks","HR"], ["Mstar - vjet","MS_V"], ["Time - Lbol / Mcor","TLM"], ["Disk radial profiles","DRP"], ["Lbol - Lshock","LL"], [" Time - Mdot","TMdot"], ["Lbol - L(Ly)","LLLy"], ["Tstar - Lint","TS_L"]] customtkinter.set_default_color_theme("dark-blue") # Themes: "blue" (standard), "green", "dark-blue" customtkinter.set_appearance_mode("system") # Appearance: "system" (standard), "dark", "light" class RadioButtonFrame(customtkinter.CTkFrame): def __init__(self, *args, header_name="RadioButtonFrame", **kwargs): super().__init__(*args, **kwargs) self.header_name = header_name self.header = customtkinter.CTkLabel(self, text=self.header_name) self.header.grid(row=0, column=0, padx=5, pady=5) self.radio_button_var = customtkinter.StringVar(value="") self.radio_buttons = [] col = 0 row = 0 for graph_type in graph_types: text, value = graph_type radio_button = customtkinter.CTkRadioButton(self, text=text, value=value, variable=self.radio_button_var) radio_button.grid(row=row, column=col, padx=5, pady=5, sticky="W") self.radio_buttons.append(radio_button) row += 1 if (row == 20): col += 1 row = 0 for button in self.radio_buttons: print (button) class App(customtkinter.CTk): def __init__(self): super().__init__() self.geometry("1024x768") self.title("RadioButtonFrame test") # create radio button frame 1 with print button self.radio_button_frame_1 = RadioButtonFrame(self, header_name="Graph Selections") self.radio_button_frame_1.grid(row=0, column=0, padx=20, pady=20) self.frame_1_button = customtkinter.CTkButton(self, text="Print value of frame", command=self.print_value_frame) self.frame_1_button.grid(row=1, column=0, padx=20, pady=10) def print_value_frame(self): print(f"Frame 1 value: {self.radio_button_frame_1.get_value()}") if __name__ == "__main__": app = App() app.mainloop()