-1

SS of tkinter window

Here's my code snippet

footer_frame = tk.Frame()
tk.Label(footer_frame, text = 'by .....', font = 'arial 10', padx=5, pady=5).pack(side = tk.RIGHT, anchor='se')
footer_frame.pack(tk.BOTTOM)
Mohit
  • 31
  • 4
  • Do you want to move the whole label, or just the text of the label? Have you tried packing the label on the right? – Bryan Oakley Nov 05 '20 at 18:17
  • @BryanOakley How to package it to the right? – Mohit Nov 05 '20 at 19:02
  • What is _it_? Your answer is no more clear than the question. Do you want the actual label _widget_ to be on the right, or do you want the widget to fill the bottom but have the _text_ to the right? And again, if you want it on the right, have you tried packing it on the right? – Bryan Oakley Nov 05 '20 at 19:36
  • I want to move the label widget to the right. And I have tried to pack it to the right using side=tk.RIGHT, it's not working – Mohit Nov 06 '20 at 03:30
  • It is because you did not expand the footer to fill all the horizontal space. – acw1668 Nov 06 '20 at 04:22

1 Answers1

2

To put the label all the way to the right inside the footer, the simplest way is to use pack and telling it to be on the right side.

Since you didn't have footer_frame fill the bottom, it's going to be centered by default. And since a frame shrinks to fit its contents, the label will also appear centered.

Here's an example, which uses side='right' for the label, and fill='x' for the footer frame. I gave the label a distinctive color so that you can see where it is in relation to the window and frame.

import tkinter as tk

root = tk.Tk()
root.geometry("400x200")
footer_frame = tk.Frame(root)
label = tk.Label(footer_frame, text="by .....", background="bisque")

footer_frame.pack(side="bottom", fill="x")
label.pack(side="right")

root.mainloop()

screenshot

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685