t在框架内对齐

2024-04-23 10:14:54 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我正在使用的GUI监视器: enter image description here

我的代码是残暴的,因为我觉得我是在一起破解它,但我希望我的对齐问题与我设置框架的方式有关,所以可能我可以省去你的小细节,并张贴出来。如果没有,让我知道,我可以张贴更多。在

这就是我的根:

weather_root = Frame(root, bg = 'orange').grid(row = 0, column = 0,sticky = NW)

forecast_root = Frame(weather_root, bg = 'blue')
forecast_root.grid(row = 0, column =1, rowspan = 8,  sticky = NSEW)

time_root = Frame(forecast_root, bg = 'red')
time_root.grid(row = 0, column = 7,sticky = NE)

commute_root = Frame(time_root)
commute_root.grid(column = 0)

quote_root = Frame(forecast_root, bg = 'yellow')
quote_root.grid(column = 0, columnspan = 8, rowspan = 4,sticky = 'S')

#I have these spanning columns to get in the description of the article
news_root = Frame(root, bg = 'green')
news_root.grid(row = 8, column = 0, columnspan = 5, sticky = W)

sport_root = Frame(root, bg = 'purple')
sport_root.grid(column = 0, columnspan = 4,sticky = W)

scores_root = Frame(root, bg = 'indianred')
scores_root.grid(row = 8, column = 7, sticky = N)

football_root = Frame(scores_root, bg = 'orange')
football_root.grid(column = 0)

business_root = Frame(football_root, bg = 'yellow')
business_root.grid(column = 0)

# This color doesn't seem to be getting picked up
stocks_root = Frame(business_root, bg = 'black')
stocks_root.grid(column = 0)

我想做的是把分数/商业新闻/股票报价推到左边,对照世界新闻,把最上面的时间放在蓝色的盒子里,这样盒子就跨越了整个顶部。在

我试着把它和《世界新闻》放在同一个框架里,但得到的却是: enter image description here

这是额外的(不重要),但当我尝试的时候真的搞砸了,所以没有按我的运气,但我希望股票报价在该部分的单独列中,这样我可以放入一些条件格式。非常感谢!在


Tags: 框架timecolumnrootbusinessframe新闻grid
1条回答
网友
1楼 · 发布于 2024-04-23 10:14:54

在顶部和底部使用额外的框架,然后将框架放在它们内部所需的位置。在

import sys
if sys.version_info[0] < 3:
    import Tkinter as tk     ## Python 2.x
else:
    import tkinter as tk     ## Python 3.x

root=tk.Tk()
root.geometry("300x500+1000+10")
blue_frame=tk.Frame(root, bg="blue", height=100, width=200)
blue_frame.grid(row=0, columnspan=2, stick="nsew") ## <  sticky=fill both columns

green_frame=tk.Frame(root, bg="green", height=300, width=200)
green_frame.grid(row=2, column=0)

yellow_frame=tk.Frame(root, bg="yellow", height=300, width=100)
yellow_frame.grid(row=2, column=1)

tk.Button(root, text="Exit", bg="orange",
          command=root.quit).grid(row=20)
root.mainloop()

相关问题 更多 >