[英]Formatting Labels TKinter python 2.7
from Tkinter import *
import sys
sys.path.append("/Users/bry/Documents/Python/proj")
import stack
window = Tk()
colors=["gold","pink","blue","red","orange","purple","teal","green","yellow","violet","black","silver","white"]
firstGame = stack.blockWorldGame()
window.title("World Block Problem Simulator")
width_value = window.winfo_screenwidth()
height_value = window.winfo_screenheight()
window.geometry("%dx%d+0+0"%(width_value,height_value))
headerFrame = Frame(window)
headerFrame.pack()
headerLabel = Label(headerFrame , text="World Block Simulator!",fg="red",font="times 50 bold italic underline")
headerLabel.pack()
startingFrame = Frame(window)
startingFrame.pack()
startingProgramLabel = Label(startingFrame, text="Starting World Block State" , font="times 20 ")
startingProgramLabel.pack()
FrameContent = Frame(window)
FrameContent.pack()
for array in range([[A],[B,C],[D,E]]):
frame = Frame(FrameContent)
frame.pack(side=LEFT,expand=False)
for block in range(len(firstGame.board[array])):#putting blocks in the same stack to the same frame
blockLabel = Label(frame,text=firstGame.board[array][block],bg=colors[array],width=30,height=3)
blockLabel.pack()
window.mainloop()
Basically through this code i am attempting to reflect the board state as i solve the world block problem however i am having some issues in representing the blocks in the correct format on the GUI 基本上通过此代码,当我解决世界障碍问题时,我试图反映电路板的状态,但是在以正确格式在GUI上显示块时,我遇到了一些问题
Upon running this set of code i will get the result of A,BC,DE. 运行这组代码后,我将得到A,BC,DE的结果。 However A block wont be reflected at the same position of B where it should be, it will be floating at a height in the middle of both B & C. 但是,A块不会在B应该位于的相同位置处反射,它将漂浮在B和C中间的高度处。
Can someone tell me how to make it such that A is inline with B and D 有人可以告诉我如何使A与B和D内联
You need to pack the blockLabel
from bottom to top inside frame
as below: 您需要按如下所示从内部frame
底部到顶部打包blockLabel
:
for array in range([[A],[B,C],[D,E]]):
frame = Frame(FrameContent)
frame.pack(side=LEFT,fill=Y) # added fill=Y
for block in range(len(firstGame.board[array])):
blockLabel = Label(frame,text=firstGame.board[array][block],bg=colors[array],width=30,height=3)
blockLabel.pack(side=BOTTOM) # added side=BOTTOM
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.