CTkScrollableDropdown icon indicating copy to clipboard operation
CTkScrollableDropdown copied to clipboard

Bug and Fix of Dropdown displaying only below the OptionMenu/ComboBox

Open Annajiraochalla opened this issue 1 year ago • 0 comments

Hi @Akascape, Please check the following.

Bug Description: The dropdown only displays below the CTkOptionMenu / CTkComboBox.

def place_dropdown(self):
    self.x_pos = self.attach.winfo_rootx() if self.x is None else self.x + self.attach.winfo_rootx()
    self.y_pos = self.attach.winfo_rooty() + self.attach.winfo_reqheight() + 5 if self.y is None else self.y + self.attach.winfo_rooty()
    self.width_new = self.attach.winfo_width() if self.width is None else self.width
    
    if self.resize:
        if self.button_num<=5:      
            self.height_new = self.button_height * self.button_num + 55
        else:
            self.height_new = self.button_height * self.button_num + 35
        if self.height_new>self.height:
            self.height_new = self.height

    self.geometry('{}x{}+{}+{}'.format(self.width_new, self.height_new,
                                        self.x_pos, self.y_pos))
    self.fade_in()
    self.attributes('-alpha', self.alpha)
    self.attach.focus()

Fix: Modifying the self.y_pos based on the root position,. Now, it will check the screen height and then automatically displays above the CTkOptionMenu / CTkComboBox if needed.

def place_dropdown(self):
  self.x_pos = self.attach.winfo_rootx() if self.x is None else self.x + self.attach.winfo_rootx()
  
  if self.attach.winfo_screenheight() - self.attach.winfo_rooty() > self.height_new:
      self.y_pos = self.attach.winfo_rooty() + self.attach.winfo_reqheight() + 5 if self.y is None else self.y + self.attach.winfo_rooty()
  else: 
      self.y_pos = self.attach.winfo_rooty() - self.height_new if self.y is None else self.y + self.attach.winfo_rooty() - self.height_new
      
  self.width_new = self.attach.winfo_width() if self.width is None else self.width
  
  if self.resize:
      if self.button_num <= 5:      
          self.height_new = self.button_height * self.button_num + 55
      else:
          self.height_new = self.button_height * self.button_num + 35
      if self.height_new > self.height:
          self.height_new = self.height

  self.geometry('{}x{}+{}+{}'.format(self.width_new, self.height_new,
                                  self.x_pos, self.y_pos))
  self.fade_in()
  self.attributes('-alpha', self.alpha)
  self.attach.focus()

Annajiraochalla avatar Apr 08 '24 01:04 Annajiraochalla