我的代码非常糟糕,因为我觉得我在一起攻击它,但我希望我的对齐问题与我设置框架的方式有关,所以我可能只是饶了你细节和帖子。如果没有,请告诉我,我可以发布更多内容。
这就是我的根源:
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)
我想要做的是将分数/商业新闻/股票报价推向左边对抗世界新闻,并将时间放在蓝色框内,以便该框横跨整个顶部。
这是额外的(不是关键的),但是当我尝试这样做时没有按下我的运气真的搞砸了,但我希望股票报价在该部分的单独列中,所以我可以放入一些条件格式。非常感谢!
答案 0 :(得分:2)
在顶部和底部使用额外的框架,然后在您想要的位置使用其中的框架。
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()