2017-10-28 56 views
0

這是GUI監控我的工作: enter image description here的Tkinter比對內框架

我的代碼是殘酷的,因爲我覺得像我黑客在一起,但我希望我的對齊問題有與我設置框架的方式有關,所以我可能只是將你的小細節留給你併發布。如果沒有,讓我知道,我可以發佈更多。

這是我的根:

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

這是額外的(並不重要),但真火起來的時候,我嘗試了沒有按我的運氣,但我希望將股票報價放在該部分的單獨列中,以便我可以輸入一些條件格式。非常感謝!

回答

1

對頂部和底部使用額外的框架,然後在您想要的位置使用其中的框架。

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()