j4321 / tkcalendar

Calendar widget for Tkinter
https://pypi.python.org/pypi/tkcalendar
GNU General Public License v3.0
97 stars 33 forks source link

the calendar drop leaves the screen #100

Open K3yr0nym0us opened 1 year ago

K3yr0nym0us commented 1 year ago

If the Entry of the calendar is set very low, when it is opened it leaves the screen, this makes it not possible to interact with it, they should make it open upwards in these cases where it is very close to the bottom edge of the screen, if this It can be configured, it should be in the documentation, which I did not find.

Wolf-SO commented 1 year ago

With what OS and Python version are you observing this?

K3yr0nym0us commented 1 year ago

@Wolf-SO latest version of python windows 10

Wolf-SO commented 1 year ago

@j4321 I can confirm this issue.

@K3yr0nym0us I just realized (if I'm right) that this doesn't depend on OS or Python (tkinter), thanks for the info anyway.

K3yr0nym0us commented 1 year ago

@Wolf-SO I really need help, I am very close to the delivery date of the project and I must correct this. As you can see, the widget leaves the screen when positioned at the bottom instead of opening at the top. Screenshot 2023-03-02 100639

K3yr0nym0us commented 1 year ago

@Wolf-SO I was reading the documentation and it says that we need babel for this widget... I did not install babel, will that be my mistake?

Wolf-SO commented 1 year ago

Sorry to tell you this: I'm not a maintainer or developer of this package. And have no time to look into this earlier than tomorrow evening (CET). What I'd try in your position now is to experiment with the _top_cal member of the DateEntry object, it's a normal tkinter Toplevel window. This object exists right after creating the DateEntry object but is hidden. Maybe you find the right event to bind a handler to.

K3yr0nym0us commented 1 year ago

@Wolf-SO Thanks for the comments, I will look for information on the aforementioned. I really appreciate your time.

Wolf-SO commented 1 year ago

Here is what I found out:

from tkcalendar import Calendar, DateEntry
import tkinter as tk

root = tk.Tk()
root.title("j4321/tkcalendar #100 (drop down)")
root.geometry("360x100")

# at least in Windows the task bar is ignored here:
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

print(f"Screen: {screen_width}x{screen_height}")

entry = DateEntry(
    root,
    width=12,
    background="darkblue",
    foreground="white",
    borderwidth=2,
    year=2010,
)
entry.pack(padx=10, pady=10)

# create a move and resize handler and bind it to the entry:
def configure_handler(entry):
    # this is the actual handler:
    def handler(event):
        widget = event.widget
        # The handler is called for all widgets in the toplevel. We
        # only want to move the toplevel window itself if necessary.
        if widget == entry._top_cal:
            must_move = False
            ey = entry.winfo_rooty()
            wx = widget.winfo_rootx()
            wy = widget.winfo_rooty()
            ww = widget.winfo_width()
            wh = widget.winfo_height()
            if wx+ww >= screen_width:
                must_move = True
                wx = screen_width-ww;
            elif wx < 0:
                must_move = True
                wx = 0
            if wy+wh >= screen_height:
                must_move = True
                wy = ey-wh;
            elif wy < 0:
                must_move = True
                wy = 0
            if must_move:
                widget.geometry(f"{wx:+d}{wy:+d}")
    return handler

entry._top_cal.bind("<Configure>", configure_handler(entry))

root.mainloop()

This moves the calendar view (if necessary) to a position that makes it completely visible.

There is one problem with this approach: The screen dimensions ignore that there is a task bar that overlaps toplevel windows. I don't have an idea how to circumvent this issue right now.

K3yr0nym0us commented 1 year ago

@Wolf-SO Incredible friend you are a God, you do not imagine the tremendous help to do me, we should label a developer of this widget so that it implements it in the native code since it is something basic of a widget, although I do not think they do it because the project has been abandoned for years. @j4321 @nprobert I know that the project has been abandoned for a long time but could you add this? It seems to me a basic and increasing function.

Wolf-SO commented 1 year ago

@K3yr0nym0us You are welcome. I'll turn it into a pull request tomorrow as to ease the integration, hopefully @j4321 will find the time to merge it then…

K3yr0nym0us commented 1 year ago

@Wolf-SO when you do, share the link to support the pull request. thanks for your time master!

Wolf-SO commented 1 year ago

Pull request #101 should fix this issue. But as @K3yr0nym0us already stated, the project seems to be abandoned.

nprobert commented 1 year ago

In our case, our app is obsolete and have no need for the calendar. We have moved onto Python3 with PySide2 (QT5) and left Tk far behind.

OogieM commented 1 year ago

In our case, our app is obsolete and have no need for the calendar. We have moved onto Python3 with PySide2 (QT5) and left Tk far behind.

I'd love to leave Tk behind but can't due to a combination of licensing issues and cross platform capability with a tiny (as in 2 people )programming staff, for a not for profit open source project.

Not everyone has the luxury of moving on to something else.

I have had my own problems with the calendar and have been trying to work around them.

Would like to know the process for getting more people allowed to be developers or maintainers of this project.