2014-01-08 44 views
1

我想獲得下面的Tkinker圖像。我只需要將標籤設置到所需的位置。無法將多個標籤設置到左側,我該怎麼做?

這是我想要的方向。 enter image description here 我不能複製這個,因爲框架不會允許多個東西設置爲同一側,左或右。 enter image description here

這裏是我以前寫這個GUI的源代碼:

master = Tk.Tk() 
master.title('Program Application') 
Folder(10) 
print "VSM activated input range first" 
################### Declare button and respective method ################### 
button = Tk.Button(text='VSM', command=VSM, fg="red") 
button.config(height = 8, width = 80) 
button.pack() #pack is needed to display the button 
bluebutton = Tk.Button(text="AGM Folder",command= lambda: Folder(0), fg="blue").pack(side = LEFT) 
bluebutton = Tk.Button(text="VSM Folder",command= lambda: Folder(1), fg="blue").pack(side = RIGHT) 
Label(text='Correct Range for Gradient\nOP X2 X1\nIP X2 X1').pack(side=TOP,padx=10,pady=10) 
################### Use 3 frames to contains entries, buttons ################### 
frameX2 = Frame(master) 
frameX2.pack(side=LEFT, expand=1, anchor=E) 
entryX2 = Entry(frameX2, width=10) 
entryX2.pack(side=TOP,padx=10,pady=10) 
entryX2IP = Entry(frameX2, width=10) 
entryX2IP.pack(side=TOP,padx=10,pady=10) 
frameButton = Frame(master) 
frameButton.pack(side=LEFT) 
Tk.Button(frameButton, text='Input Range',command= lambda: Folder(2), fg="red").pack(padx=10, pady=10) 
frameX1 = Frame(master) 
frameX1.pack(side=LEFT, expand=1, anchor=W) 
entryX1 = Entry(frameX1,width=10) 
entryX1.pack(side=TOP,padx=10,pady=10) 
entryX1IP = Entry(frameX1,width=10) 
entryX1IP.pack(side=TOP,padx=10,pady=10) 
######### Loop ############ 
master.mainloop() # Continue loop till user close tab 
print "End of Program" 
entryX1.pack(side=TOP,padx=10,pady=10) 
entryX1IP = Entry(frameX1,width=10) 
entryX1IP.pack(side=TOP,padx=10,pady=10) 
######### Loop ############ 
master.mainloop() # Continue loop till user close tab 

回答

1

好像grid對你更合適的佈局。

master = Tk.Tk() 
master.title('Program Application') 
#Folder(10) 
print "VSM activated input range first" 
################### Declare button and respective method ################### 
button = Tk.Button(text='VSM', command=VSM, fg="red") 
button.config(height = 8, width = 80) 
button.pack() #pack is needed to display the button 
bluebutton = Tk.Button(text="AGM Folder",command= lambda: Folder(0), fg="blue").pack(side = LEFT) 
bluebutton = Tk.Button(text="VSM Folder",command= lambda: Folder(1), fg="blue").pack(side = RIGHT) 
Label(text='Correct Range for Gradient').pack(side=TOP,padx=10,pady=10) 



# ---------------------- change from here ------------------------- 
frame = Frame(master) 
frame.pack(side=LEFT, expand=1) 

Label(frame, text='X2').grid(row=0, column=1) 
Label(frame, text='X1').grid(row=0, column=3) 
Label(frame, text='OP').grid(row=1, column=0) 
Label(frame, text='IP').grid(row=2, column=0) 

entryX2 = Entry(frame, width=10) 
entryX2.grid(row=1, column=1, padx=10, pady=10) 
entryX2IP = Entry(frame, width=10) 
entryX2IP.grid(row=2, column=1, padx=10, pady=10) 
Tk.Button(frame, text='Input Range', command=lambda: Folder(2), fg="red").grid(row=0, column=2, rowspan=3, padx=10, pady=10) 
entryX1 = Entry(frame,width=10) 
entryX1.grid(row=1, column=3) 
entryX1IP = Entry(frame,width=10) 
entryX1IP.grid(row=2, column=3) 
# ---------------------- to here ------------------------- 
master.mainloop() # Continue loop till user close tab 

輸出:

enter image description here

+0

這是非常好,長得這麼整潔。 – user2837162