简体   繁体   English

如何在右上角显示时间和日期,同时在左上角显示温度?

[英]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.

相关问题 如何在任何计算机的右上角找到tkinter窗口? - how can I get a tkinter window in the top right corner of any computer? 如何将 QlistWidget 中的图标项从上到下而不是从左到右插入小部件或显示? - How can I have the icon items in my QlistWidget insert into the widget, or display, from top to bottom and not left to right? 如何从左到右和从上到下对轮廓进行排序? - How can I sort contours from left to right and top to bottom? 如何将每个圆圈连接到 pygame 的左上角? - How do I connect each circle to the top left corner in pygame? 如何在 QGIS 的右上角设置 DockWidget? - How to set DockWidget at Top Right corner of QGIS? 如何将Legend的右上角锚定到matplotlib中的轴的右上角? - How to anchor top right corner of Legend to top right corner of Axes in matplotlib? 如何在 Seaborn 的配对图中绘制右轴和上轴并移除左轴和下轴? - How can I draw the right and top axis and remove the left and bottom axis in a Pairplot of Seaborn? 如何提取图像中白色蒙版(多边形)的坐标(上、下、左、右)? - How can i extract out the coordinates (top, bottom, left, right) of white mask (polygon) in image? 如何以一致的方式从左到右和从上到下对轮廓进行排序 - How can I sort contours from left to right and top to bottom in a consistent manner 如何从左上角开始向gridlayout添加小部件 - How to add widget to gridlayout starting from top-left corner
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM