Brōtsyorfuzthrāx
Brōtsyorfuzthrāx

Reputation: 4749

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).

Upvotes: 6

Views: 9380

Answers (2)

user10773662
user10773662

Reputation: 1

A good way of doing this is if you can't stick it in the corner to where it stays there, is to make it unresizable.

`from tkinter import *
root = Tk()
root.title("What ever you want")
root.resizable(0,0)
bt = Button(root, text="Click Me!")
bt.grid(row=1, column=1)`

This is a great way to do do it especially when you are making small logins!

I hope this helped you all!

Make sure to reply! Thanks!

Upvotes: 0

Brōtsyorfuzthrāx
Brōtsyorfuzthrāx

Reputation: 4749

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.)

Upvotes: 10

Related Questions