Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter; Put a widget in the lower-right corner using place()

[Note: I'm only asking this question in order to post the answer, because I found the answer before I finished asking, and I thought someone else might want to know. My answer is purposefully an answer, and is not part of the question.]

How do I use Tkinter's myWidget.place() method to get the widget (fully visible) in the exact lower-right corner of the screen? I've tried using anchor=SE, but the widget disappears (although it's there; it's just off the screen somewhere). The following code works well for the upper-right corner:

self.entry.place(relx=1, x=0, y=-1, anchor=NE);

But, changing the anchor to SE doesn't do what I expected.

I don't want to use pack or grid with this.

Anyway, I want this to go on top of another widget that is already there without being packed into it (because that gives me issues, and I need a new widget for every tab that way, whereas this way I would only need one widget).

like image 300
Brōtsyorfuzthrāx Avatar asked Feb 13 '23 05:02

Brōtsyorfuzthrāx


1 Answers

This will allow you to get the widget in the lower-right corner (and automatically takes into account the widget's size).

myWidget.place(rely=1.0, relx=1.0, x=0, y=0, anchor=SE)

1.0 for rely means the bottom of the master widget. 1.0 for relx means the right side of the master widget.

In response to Superior's comment asking for my source, I don't recall where I first found it offhand, but the documentation for the place method tells pretty much what I said in this answer. Go to the python3 interpreter, type import tkinter; type help(tkinter.Text.place) and look at relx and rely. "relx=amount - locate anchor of this widget between 0.0 and 1.0 relative to width of master (1.0 is right edge)" and "rely=amount - locate anchor of this widget between 0.0 and 1.0 relative to height of master (1.0 is bottom edge)". (Yes, the widget I was positioning was actually a modified Text widget—not an Entry widget, even though I called it self.entry in the question, since I like to use Text widgets where people normally use Entry widgets.)

like image 116
Brōtsyorfuzthrāx Avatar answered Feb 15 '23 10:02

Brōtsyorfuzthrāx