I was trying to use the set_widget_scale
function to resize my widgets based on the resolution of the window, when I resize the widgets on the main page it works fine when the resolution is chosen, when I go to the other page it raises this error:
("_tkinter.TclError: invalid command name ".!ctkframe.!ctkoptionmenu.!dropdownmenu"")
I tried multiple workarounds with no success, namely:
- …
I used this function to resize my other page.
def Resize2(self):
scaling_factors = {
"640x480": 0.62, "720x480": 0.85, "720x576": 0.90, "800x600": 0.95,
"1024x768": 1.0, "1152x864": 1.05, "1176x664": 1.05, "1280x720": 1.1,
"1280x768": 1.1, "1280x800": 1.1, "1280x960": 1.1, "1280x1024": 1.1,
"1360x768": 1.15, "1366x768": 1.18, "1440x900": 1.2, "1440x1050": 1.23,
"1440x1080": 1.25, "1600x900": 1.3, "1600x1024": 1.33, "1680x1050": 1.35,
"1920x1080": 1.4
}
ct.set_widget_scale(scaling_factors.get(new_Res , 1.0)
This is the other page that resize is not working in.
def Compulsory(self):
for i in self.winfo_children():
i.destroy()
self.grid_columnconfigure((0),weight=1)
self.grid_columnconfigure((1,2,3,4),weight=0)
self.grid_rowconfigure((0,1,2,3),weight=1)
self.grid_rowconfigure((4,5),weight=0)
self.Athlete_frame = ct.CTkFrame(self , width = 400)
self.Athlete_frame.grid_columnconfigure((1,2) , weight = 1)
self.Athlete_frame.grid_rowconfigure((0,1,2,3,4,5,6,7,8,9) , weight = 0)
self.Athlete_frame.grid(row = 0 , column = 0 , columnspan = 1 , rowspan = 1 , padx = 20 , pady = 20 , sticky = 'snwe')
self.Results_frame = ct.CTkFrame(self , width = 450)
self.Results_frame.grid(row = 0 , column = 1 , columnspan = 1 , rowspan = 1 , padx = 20 , pady = 20 , sticky = 'snwe')
self.Deduction_frame = ct.CTkFrame(self , width = 400)
self.Deduction_frame.grid_rowconfigure((2,3),weight=1)
self.Deduction_frame.grid(row = 1 , column = 0 , columnspan = 3 , rowspan = 2 , padx = 20 , pady = 20 , sticky = 'snew')
self.Athlete_lbl = ct.CTkLabel(self.Athlete_frame , text = "Add Athlete" , font = ct.CTkFont(family = "Times New Roman" , size = 20 , weight = 'bold'))
self.Athlete_lbl.grid(row = 0 , column = 1 , padx = 20 , pady = (10, 5) , sticky = 'n')
self.Name_lbl = ct.CTkLabel(self.Athlete_frame , text = "Athlete's Name:" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.Name_lbl.grid(row = 1 , column = 0 , padx = 20 , pady = (5 , 5))
self.Age_lbl = ct.CTkLabel(self.Athlete_frame , text = "Athlete's Age:" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.Age_lbl.grid(row = 2 , column = 0 , padx = 20 , pady = (5 , 5))
self.Team_lbl = ct.CTkLabel(self.Athlete_frame , text = "Athlete's Team:" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.Team_lbl.grid(row = 3 , column = 0 , padx = 20 , pady = (5 , 5))
self.Level_lbl = ct.CTkLabel(self.Athlete_frame , text = "Level:" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.Level_lbl.grid(row = 5 , column = 0 , padx = 20 , pady = (5 , 5))
self.Apparatus_lbl = ct.CTkLabel(self.Athlete_frame , text = "Apparatus:" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.Apparatus_lbl.grid(row = 4 , column = 0 , padx = 20 , pady = (5 , 5))
self.Name_ent = ct.CTkEntry(self.Athlete_frame , width = 300 , font = ("Times New Roman", 20))
self.Name_ent.grid(row = 1 , column = 1 , padx = 5 , pady = 5 , sticky = 'n')
self.Age_ent = ct.CTkEntry(self.Athlete_frame , width = 300 , font = ("Times New Roman", 20))
self.Age_ent.grid(row = 2 , column = 1 , padx = 5 , pady = 5 , sticky = 'n')
self.Team_ent = ct.CTkEntry(self.Athlete_frame , width = 300 , font = ("Times New Roman", 20))
self.Team_ent.grid(row = 3 , column = 1 , padx = 5 , pady = 5 , sticky = 'n')
self.Apparatus_menu = ct.CTkOptionMenu(self.Athlete_frame , width = 300 , values = ["Vault","Uneven Bars","Balance Beam","Floor"] , font = ct.CTkFont(family = "Times New Roman" , size = 20, weight ='bold') , fg_color = "#565b5e" , button_color = "#343638" , button_hover_color = "#343638")
self.Apparatus_menu.grid(row = 4 , column = 1 , padx = 5 , pady = 5 , sticky = 'n')
self.Level_menu = ct.CTkOptionMenu(self.Athlete_frame , width = 300 , values = ["1","2","3","4","5","6","7","8","9","10"] , font = ct.CTkFont(family = "Times New Roman" , size = 20, weight ='bold') , fg_color = "#565b5e" , button_color = "#343638" , button_hover_color = "#343638")
self.Level_menu.grid(row = 5 , column = 1 , padx = 5 , pady = 5 , sticky = 'n')
self.bu1 = ct.CTkButton(self.Deduction_frame ,text = "0.05" , width = 50 , font = ("Times New Roman",72) , command = lambda : Deduction(1) , fg_color = "#858585" , hover_color = "#858585")
self.bu1.grid(row = 0 , column = 0 , padx = (10 , 30) , pady = 10)
self.bu2 = ct.CTkButton(self.Deduction_frame ,text = "0.1" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(2) , fg_color = "#858585" , hover_color = "#858585")
self.bu2.grid(row = 0 , column = 1 , padx = 30 , pady = 10)
self.bu3 = ct.CTkButton(self.Deduction_frame ,text = "0.2" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(3) , fg_color = "#858585" , hover_color = "#858585")
self.bu3.grid(row = 0 , column = 2 , padx = 30 , pady = 10)
self.bu4 = ct.CTkButton(self.Deduction_frame ,text = "0.3" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(4) , fg_color = "#858585" , hover_color = "#858585")
self.bu4.grid(row = 0 , column = 3 , padx = 30 , pady = 10)
self.bu5 = ct.CTkButton(self.Deduction_frame ,text = "0.4" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(5) , fg_color = "#858585" , hover_color = "#858585")
self.bu5.grid(row = 0 , column = 4 , padx = (30 , 10) , pady = 10)
self.bu6 = ct.CTkButton(self.Deduction_frame ,text = "0.5" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(6) , fg_color = "#858585" , hover_color = "#858585")
self.bu6.grid(row = 1 , column = 0 , padx = (10 , 30) , pady = 10)
self.bu7 = ct.CTkButton(self.Deduction_frame ,text = "0.6" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(7) , fg_color = "#858585" , hover_color = "#858585")
self.bu7.grid(row = 1 , column = 1 , padx = 30 , pady = 10)
self.bu8 = ct.CTkButton(self.Deduction_frame ,text = "0.7" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(8) , fg_color = "#858585" , hover_color = "#858585")
self.bu8.grid(row = 1 , column = 2 , padx = 30 , pady = 10)
self.bu9 = ct.CTkButton(self.Deduction_frame ,text = "0.8" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(9) , fg_color = "#858585" , hover_color = "#858585")
self.bu9.grid(row = 1 , column = 3 , padx = 30 , pady = 10)
self.bu10 = ct.CTkButton(self.Deduction_frame ,text = "0.9" , width = 140 , font = ("Times New Roman",70) , command = lambda : Deduction(10) , fg_color = "#858585" , hover_color = "#858585")
self.bu10.grid(row = 1 , column = 4 , padx = (30 , 10) , pady = 10)
self.Back_button = ct.CTkButton(self.Deduction_frame , text = "Back" , width = 140 , font = ("Times New Roman",30) , command = self.Home , fg_color = "#858585" , hover_color = "#858585")
self.Back_button.grid(row = 4 , column = 0 , padx = (10 , 30) , pady = 15)
self.Next_button = ct.CTkButton(self.Deduction_frame , text = "Next Athlete" , width = 140 , font = ("Times New Roman",30) , command = self.Done , fg_color = "#858585" , hover_color = "#858585")
self.Next_button.grid(row = 4 , column = 2 , padx = 30 , pady = 15)
self.Finish_button = ct.CTkButton(self.Deduction_frame , text = "Finish" , width = 140 , font = ("Times New Roman",30) , command = lambda : (self.Browse() , self.Finish()) , fg_color = "#858585" , hover_color = "#858585")
self.Finish_button.grid(row = 4 , column = 4 , padx = (30 , 10) , pady = 15)
self.lbl = ct.CTkLabel(self.Results_frame , width = 250 , text = "" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.lbl.grid(row = 0 , column = 0 , padx = 20 , pady = 20)
self.Deductions_lbl = ct.CTkLabel(self.Results_frame , text = "" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.Deductions_lbl.grid(row = 1 , column = 0 , padx = 20 , pady = 20)
self.lbl1 = ct.CTkLabel(self.Results_frame , text = "" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.lbl1.grid(row = 2 , column = 0 , padx = 20 , pady = 20)
self.Total_lbl = ct.CTkLabel(self.Results_frame , text = "" , font = ct.CTkFont(family = "Times New Roman" , size = 20 ))
self.Total_lbl.grid(row = 3 , column = 0 , padx = 20 , pady = 20)
self.Resize2()
And I know please don’t yell at me for not organizing my code and thank you :)!!
I tried to change my function, change the way that the application goes to the compulsory page…etc.
Mohammad Ali Naanouh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.