CustomTkinter
CustomTkinter copied to clipboard
why is function called by OptionMenu starting on it's own without any input
self.OptionmenuTheme = customtkinter.CTkOptionMenu(self.window,
values=["Green", "Blue", "Dark-Blue", "Red"],
command=self.change_theme,
hover=True)
self.OptionmenuTheme.place(relx=0.95, rely=0.45, anchor="e")
self.OptionmenuTheme.set(Option_th_df)
The switch toggle is not doing anything is there some problem with the window itself? the window is a CTkToplevel
it still happens but I think it might be something with the CTkToplevel window, because switch.toggle also isn't working as intended
What do you mean by "not working as intended"? Can you give me a code example?
This is the whole settings window
def settings(self):
if self.window == None:
self.window = customtkinter.CTkToplevel(self)
Width = 420
Height = 240
self.window.title(SelectedLanguage["Settings Button"])
self.window.wm_iconbitmap(f"{L.Universal['Necessary Files Folder']}\\icon.ico")
self.window.attributes('-topmost',True)
self.window.attributes('-topmost',False)
self.window.minsize(420, 200)
self.window.maxsize(420, 200)
self.window.protocol("WM_DELETE_WINDOW", self.closed_set_window)
current_screen = get_monitor_from_coord(self.window.winfo_x(), self.window.winfo_y())
screen_width = current_screen.width
screen_height = current_screen.height
x_cord = int((screen_width / 2) - (Width / 2))
y_cord = int((screen_height / 2) - (Height / 2))
self.window.geometry("{}x{}+{}+{}".format(Width, Height, x_cord, y_cord))
self.warningLabel = customtkinter.CTkLabel(self.window,
text=SelectedLanguage["Warning Label"])
self.warningLabel.place(relx = 0.03,rely = 0.85)
self.switch = customtkinter.CTkSwitch(master=self.window,
text=SelectedLanguage["Theme Switch"],
command=self.theme_change,)
self.switch.toggle(0)
self.switch.place(relx=0.12, rely=0.65)
self.tooltip(self.switch, SelectedLanguage["Theme Switch Tooltip"])
self.report = customtkinter.CTkButton(self.window,
width=150,
height=25,
border_width=0,
corner_radius=8,
hover=True,
text=SelectedLanguage["Report Bug Button"],
command=self.report_command,
image=self.bug_report_img,
compound=tkinter.RIGHT)
self.report.place(relx=0.05, rely=0.3, anchor="w")
self.tooltip(self.report, SelectedLanguage["Report Bug Button Tooltip"])
self.about_bt = customtkinter.CTkButton(self.window,
width=150,
height=25,
border_width=0,
corner_radius=8,
hover=True,
text=SelectedLanguage["About Button"],
command=self.about,
image=self.about_img,
compound=tkinter.RIGHT)
self.about_bt.place(relx=0.05, rely=0.45, anchor="w")
self.tooltip(self.about_bt, SelectedLanguage["About Button Tooltip"])
self.button_get_tutorial = customtkinter.CTkButton(self.window,
width=150,
height=25,
border_width=0,
corner_radius=8,
hover=True,
text=SelectedLanguage["Tutorial Button"],
command=self.tutorial,
image=self.tutorial_img,
compound=tkinter.RIGHT)
self.button_get_tutorial.place(anchor="w", rely = 0.15, relx=0.05)
self.tooltip(self.button_get_tutorial, SelectedLanguage["Tutorial Button Tooltip"])
self.Optionmenu = customtkinter.CTkOptionMenu(self.window,
values=["Português-pt", "English"],
command=self.change_language,
hover=True)
self.Optionmenu.place(relx=0.95, rely=0.16, anchor="e")
self.Optionmenu.set(Option_lg_df)
self.OptionmenuTheme = customtkinter.CTkOptionMenu(self.window,
values=["Green", "Blue", "Dark-Blue", "Red"],
command=self.change_theme,
hover=True)
self.OptionmenuTheme.place(relx=0.95, rely=0.45, anchor="e")
self.OptionmenuTheme.set(Option_th_df)
that self.switch.toggle doesn't do anything
toggle doesn't take any argument, it just changes the state. I you want to set a specific state use select() or deselect(). Also try using these functions after the place() method.
oh my bad then
but the function still starts when the CTkToplevel window is opened
That's because select(), deselect() and toggle() all trigger the command function. But I will change it so that only toggle() triggers the command.
Im talking about the OptionMenu sorry for not being clear, but yes both the switch and the Option menu start they're "commands" when the CTkToplevel window is opened