Python Forum
[Tkinter] Combobox dropbox appear top left screen corner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Combobox dropbox appear top left screen corner
#1
I face a strange issue with the Tkinter combobox. I run this simple GUI with a combobox. A month ago, on my windows 10 the tkinter combobox start to appear at topleft corner instead of below the arrow.

from tkinter.ttk import *
window = Tk()
window.title("ComboBox list down test")
window.geometry('350x200')
combo = Combobox(window)
combo['values']= (1, 2, 3, 4, 5, "Text")
combo.current(1) #set the selected item
combo.grid(column=0, row=0)
window.mainloop()
I join link to image related to both working and not working combobox.
I have 3 computer on my desk and only one is doing this behavior.
These a corporate computer with all the same OS and same verison of win10.

I run python 3.7.7 (I try newer version and it is not fixing the issue)

Here is a preview of what i mean: drop list on the topleft corner

When using another windows 10 with the same python 3.7.7 the combobox is ok: Combobox normal

This behavior start appening on my gui out of nowhere. It start doing this a month ago. Is there propertie on the combobox to make it display correctly.

Is someone facing the same issue?

I coded some GUI in TCL TK and got the same problem, the only way to fix it was to change the tclsh.exe shell to tclsh85.exe but both of the exe file come from the same installation of active tcl 8.5.
Now it is with python Tkinter.
Anyone have an idea
Reply
#2
you can change starting position in your geometry statement,
instead of: window.geometry('350x200')
use: window.geometry('350x200+50+50')
the +50 +50 is x and y offset in pixels from upper left corner of display
it's better to use variables here, then you can calculate the values
A function with default of 10, 10 that can be overridden:
def set_geometry(width, height, xpos=10, ypos=10):
    window.geometry(width, height, xpos, ypos)

set_geometry(...)
Reply
#3
Thanks Larz60+ for the fast reply.
But this is not fixing the issue.
When the windows open from the small script execution. I move the windows at the center of the screen and clic on the combobox arrow to view the list. It appear at top left corner of the first screen on the computer.
This occur only on few computer and on others the drop is at the right position.
Reply
#4
I don't have anything that runs MS windows, so can't test.
The example that I show has a default of xpos=10, ypos=10
so essentially that is upper left corner.
try calling like:
width = 350
height = 200
xpos = 200
ypos = 200
set_geometry(width, height, xpos, ypos)
play around with xpos, ypos
it's better to create a frame withon windows, and create your combobox (and any other widgets associated ithe the combobox) within that frame, Now if you need a different group of widgets, they can be defined in a new frame, thus isolating the two (or more) groups.
Reply
#5
The dropdown list will shift to be completely visible. If I run your program and drag it down to the lower left corner of my screen, the dropdown list is drawn above and left of the combobox widget. Maybe your computer is telling the window manager that the screen is tiny. What do you get for screen dimensions when running this:
from tkinter import *
from tkinter.ttk import *
window = Tk()
print(window.winfo_screenwidth(), window.winfo_screenheight())
window.title("ComboBox list down test")
window.geometry('350x200')
combo = Combobox(window)
combo['values']= (1, 2, 3, 4, 5, "Text")
combo.current(1) #set the selected item
combo.grid(column=1, row=1)
window.mainloop()
Reply
#6
your import is incorrect
Quote:from tkinter.ttk import *
try
from tkinter import Tk
from tkinter import ttk
combo= ttk.ComboBox(#rest of it
my guess, the upper left corner is where the combox is first created and because you have not imported Tk correctly it's not tied to your widget. your code doesn't run on window 8, error Tk not defined
Reply
#7
I saw that too (missing import), but it throws an exception and the program does not run. My guess is a copy/paste error missed the top line. I added that and the program runs fine on my computer.
Reply
#8
import tkinter as tk
import tkinter.ttk as ttk


def set_geometry(window, width, height, xpos=10, ypos=10):
    window.geometry(f"{width}x{height}+{xpos}+{ypos}")


def draw_win(win, width, height, x, y):
    win.title("ComboBox list down test")
    set_geometry(win, width, height, x, y)
    # window.geometry('350x200')
    combo = ttk.Combobox(win)
    combo["values"] = (1, 2, 3, 4, 5, "Text")
    combo.current(1)  # set the selected item
    combo.grid(column=0, row=0)


def main():
    window = tk.Tk()
    width = 350
    height = 200
    x = 600
    y = 400
    draw_win(window, width, height, x, y)
    window.mainloop()


if __name__ == "__main__":
    main()
[attachment=840]
Reply
#9
Thanks for the fast response again, i am impress.

I tried the solution propose by joe_momma to modify the import without success, it is still doing the same thing.
I also try to run the code from Larz60+ and same result the drop down list still appear at top left of the first head(monitor) of my video card.

As i mention above, i face the same issue in TCL TK (homebrew GUI for the office internal use) and some of the computer started to do the same behavior months ago. For it i had to change the shell executable from tclsh.exe to tclsh85.exe and it fix this issue.

When a computer start doing this behavior it does it for TCL tk gui and for pyhton gui using Tkinter.
Reply
#10
This was a misunderstanding.
from your first post, should have looked at the image, (As a rule I skip over links, as they can be malicious, post inline to avoid this, as it's OK to post images that are not code). My understanding was completely different from what you were asking.
What I provided was code that will allow your python 'window' to move anywhere on the screen. Moving part of a tkinter widget wasn't even in my thoughts. Using GUI terms will help in future posts.
That is bizarre behaviour, and I think may be related to MS operating system (which I don't use)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] How can I sync Combobox index to other combobox index? nickzsche 2 2,382 Jan-03-2022, 12:29 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020