2017-09-05 27 views
1

我想在python的tkinter中创建一个2×2的框,这将是我的“世界”。 有没有办法在“世界”上设置X轴和Y轴?tkinter设置比例(创建一个2x2框)

是这样的:

setXscale(-1.0, +1.0); 
    setYscale(-1.0, +1.0); 
+0

所以,你只是希望创造4'frame' s在一个固定大小的2 x 2格子结构? –

+0

是的。在这个盒子里我会创建标签等 – TheCrystalShip

+0

只需使用['grid'](http://effbot.org/tkinterbook/grid.htm)而不是'pack' ... –

回答

1

这可以用.pack()方法来完成如在下面可以看到:

from tkinter import * 

root = Tk() 

top = Frame(root) 
bottom = Frame(root) 
topleft = Frame(top) 
topright = Frame(top) 
bottomleft = Frame(bottom) 
bottomright = Frame(bottom) 

lbl1 = Label(topleft, text="topleft") 
lbl2 = Label(topright, text="topright") 
lbl3 = Label(bottomleft, text="bottomleft") 
lbl4 = Label(bottomright, text="bottomright") 

top.pack(side="top") 
bottom.pack(side="bottom") 
topleft.pack(side="left") 
topright.pack(side="right") 
bottomleft.pack(side="left") 
bottomright.pack(side="right") 

lbl1.pack() 
lbl2.pack() 
lbl3.pack() 
lbl4.pack() 

root.mainloop() 

这就产生了一个top帧和bottom帧,其中每一个包含左右框架。 这些框架然后被包装在它们各自的side中。


或者,这是可以做到轻松了许多与.grid()这样的:

from tkinter import * 

root = Tk() 

topleft = Frame(root) 
topright = Frame(root) 
bottomleft = Frame(root) 
bottomright = Frame(root) 

lbl1 = Label(topleft, text="topleft") 
lbl2 = Label(topright, text="topright") 
lbl3 = Label(bottomleft, text="bottomleft") 
lbl4 = Label(bottomright, text="bottomright") 

topleft.grid(row = 0, column = 0) 
topright.grid(row = 0, column = 1) 
bottomleft.grid(row = 1, column = 0) 
bottomright.grid(row = 1, column = 1) 

lbl1.grid(row = 0, column = 0) 
lbl2.grid(row = 0, column = 0) 
lbl3.grid(row = 0, column = 0) 
lbl4.grid(row = 0, column = 0) 

root.mainloop() 

或者这样:

from tkinter import * 

root = Tk() 

lbl1 = Label(root, text="topleft") 
lbl2 = Label(root, text="topright") 
lbl3 = Label(root, text="bottomleft") 
lbl4 = Label(root, text="bottomright") 

lbl1.grid(row = 0, column = 0) 
lbl2.grid(row = 0, column = 1) 
lbl3.grid(row = 1, column = 0) 
lbl4.grid(row = 1, column = 1) 

root.mainloop()