1

I have a time, date, and weather widget I need to display in each top corners. The time displays correctly but the weather won't stay in the top left corner. I used python to code this and no matter where i anchor the weather wont go to the top left corner. I am a bit new to Tkinter so please help me and explain. THIS IS FOR SCHOOL PROJECT PLS HELP

Picture of my program

 root = Tk()
#BACKGROUND
root.configure(bg="black")

#ORGANIZATION
topFrame=Frame(root,bg="black")
topFrame.pack(side=TOP,fill=BOTH)
bottomFrame=Frame(root,bg="black")
bottomFrame.pack(side=BOTTOM,fill=BOTH)

#CLOCK WIDGET
widget=Label(topFrame,font=("helvitic",large_text_size,"bold",),bg="black",fg="white")                                       
widget.pack(side=TOP,anchor=E)
Clock()

#DAY OF THE WEEK
day_label=Label(topFrame,font=("helvitic",small_text_size,"bold"),bg="black",fg="white")
day_label.pack(side=TOP,anchor=E)
Day_Week()

#DATE
date_label=Label(topFrame,font=("helvitic",small_text_size,"bold"),bg="black",fg="white")
date_label.pack(side=TOP,anchor=E)
Date()

#WEATHER
weather_label=Label(topFrame,font=("helvitic",50,"bold"),bg="black",fg="white",)
weather_label.pack(side=LEFT,anchor=NW)
Weather()
Celscius=Label(topFrame,font=("helvitic",xlarge_text_size,"bold"),bg="black",fg="white",text="°C")
Celscius.pack(side=LEFT,anchor=N)

#WEATHER ICON
icon_label=Label(bottomFrame,font=("helvitic",50,"bold"),bg="black",fg="white",)
icon_label.pack(side=LEFT)
Icon()






#FULLSCREEN AND EXIT
root.bind("<Delete>",exit)
root.bind("<Return>",fullscrn)
root.bind("<Escape>",bckspace)





root.mainloop()


  [1]: https://i.stack.imgur.com/YbiLh.png
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Noel
  • 23
  • 4

1 Answers1

0

For a layout like this, I find it easier to use the grid geometry manager instead of pack. With the grid manager, you are packing your widgets into columns and rows, instead of side by side or on top of each other. You can configure where the widget sits in it's area of the grid, how the grid should respond to the window resizing etc.

This code puts a label in the top left, top right and bottom left of a window. They will stay there even if the window is resized.

import tkinter as tk

root = tk.Tk()

# configure the grid for resizing
root.grid_columnconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=1)
root.grid_rowconfigure(0, weight=1)
root.grid_rowconfigure(1, weight=1)

# pack labels
tk.Label(root, text='TL').grid(row=0, column=0, sticky='NW')
tk.Label(root, text='TR').grid(row=0, column=1, sticky='NE')
tk.Label(root, text='BL').grid(row=1, column=0, sticky='SW')

root.mainloop()
strava
  • 765
  • 6
  • 14
  • Thanks!Using a grid has helped me. – Noel Aug 12 '18 at 16:31
  • No problem! If this answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – strava Aug 12 '18 at 18:51
  • _"Pack tries to keep the objects in as small an area as possible, so spreading widgets into the corners is going to be difficult."_ - that's not true at all. – Bryan Oakley Aug 13 '18 at 01:21
  • Ok, I've removed that sentence from my answer. I've put a question [here](https://stackoverflow.com/q/51818550/8201979) about this, I'd appreciate it if you could take the time to answer it. Thanks – strava Aug 13 '18 at 09:08