[英]How can I get the Temperature to display in the top left corner while having the time and date in the top right?
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.
我用python编写了代码,无论我在哪里锚定天气都不会转到左上角。 I am a bit new to Tkinter so please help me and explain.
我对Tkinter有点陌生,所以请帮助我并解释一下。 THIS IS FOR SCHOOL PROJECT PLS HELP
这是针对学校项目的PLS帮助
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
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.