Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Annajiraochalla opened this issue Apr 8, 2024 · 0 comments

Comments

@Annajiraochalla
Copy link

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant